Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'em-jack'
- EM.run {
- q = EMJack::Connection.new #connect to beanstalk
- q.each_job do |job|
- puts "Got job #{job.jobid}"
- if process(job)
- r = q.delete(job)
- r.callback { puts "Deleted #{job}" }
- end
- end
- def process(job)
- # process....... mmmmmm mmmmmmm
- # if the job is successful, then return true
- return true
- # if the process failed, then return false which won't
- # remove the job from the queue and wait for the ttr
- # to expire and automatically put it back on the queue.
- # we could delete it and manually put it back on the queue
- # but this is a nice failsafe in case the server dies during
- # processing... especially if the ttr is lower like 10 seconds.
- #return false
- end
- }
Add Comment
Please, Sign In to add comment