adamwiggins / stalker

A minimalist queueing DSL for Beanstalk.
http://github.com/han/stalker
164 stars 50 forks source link

Blocking job queuing with response #19

Open kke opened 12 years ago

kke commented 12 years ago

I'd like to see something like :

response = Stalker.enqueue_with_response("sum", :a => 1, :b => 2)
or 
Stalker.enqueue_with_response("sum", :a => 1, :b => 2) do |response|
  puts "1 +2 = #{response['sum']}"
end

and the worker:

job_with_response "sum" do |args| 
  return :sum => args['a'] + args['b']
end

This would work by adding something like :respond_to => "stalker-response-#{$$}-#{SecureRandom.uuid}" to the job params, then subscribing to that queue (perhaps with a configurable timeout) where the worker will then enqueue it's return value once finished.

There could also be partial responses so one could do something like:

job_with_response "sum" do |args, response|
  response['status'] = 'going to calculate!'
  response['status_pct'] = 0
  response['sum'] = args['a'] + args['b']
  response['status'] = 'done calculating!'
  response['status_pct'] = 100
end

Getting a little carried away here.

kke commented 12 years ago

I made a pull request to han repo that provides this. https://github.com/han/stalker/pull/12