Guest User

Untitled

a guest
Apr 24th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. require 'em-jack'
  2.  
  3. EM.run {
  4. q = EMJack::Connection.new #connect to beanstalk
  5.  
  6. q.each_job do |job|
  7. puts "Got job #{job.jobid}"
  8.  
  9. if process(job)
  10. r = q.delete(job)
  11. r.callback { puts "Deleted #{job}" }
  12. end
  13. end
  14.  
  15. def process(job)
  16. # process....... mmmmmm mmmmmmm
  17.  
  18. # if the job is successful, then return true
  19. return true
  20.  
  21. # if the process failed, then return false which won't
  22. # remove the job from the queue and wait for the ttr
  23. # to expire and automatically put it back on the queue.
  24. # we could delete it and manually put it back on the queue
  25. # but this is a nice failsafe in case the server dies during
  26. # processing... especially if the ttr is lower like 10 seconds.
  27. #return false
  28. end
  29. }
Add Comment
Please, Sign In to add comment