Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Goworker - A Resque backround worker in Go

Avatar for Mike Mike
May 13, 2014

Goworker - A Resque backround worker in Go

An intro for Rubyists on background processing Resque jobs using Go

Avatar for Mike

Mike

May 13, 2014

Other Decks in Programming

Transcript

  1. What is Go? ❏ compiled (fast) ❏ strongly typed ❏

    first class functions ❏ concurrent ❏ C-style syntax
  2. ❏ a single binary ❏ polls Resque-Queues ❏ manages worker

    state ❏ dispatches jobs via goroutines What is Goworker?
  3. How does it work? Enqueue a Job in Ruby Land:

    ❏ RPOP the job from Redis ❏ parse JSON ❏ find worker func for class ❏ call worker func with args Same as: redis-cli RPUSH resque:queue:hello '{"class": "Hello", "args": ["World"]}'
  4. WTF is a worker func? ❏ takes two Arguments: ❏

    queue name ❏ Array of unspecified args ❏ returns an error on failure
  5. Putting it together Define a main-func like in C: File

    worker.go Register your worker-func: File hello_worker.go
  6. Run it! go get github.com/benmanns/goworker (install library + dependencies) go

    build (compile code + create executable) ./worker -queues=hello (run it + spawn 25 workers by default)
  7. Type assertions ❏ Type-asserting all args can be quite tedious

    ❏ want to use custom argument types ❏ define structs