Skip to content

Instantly share code, notes, and snippets.

@pkieltyka
Created November 6, 2009 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkieltyka/227995 to your computer and use it in GitHub Desktop.
Save pkieltyka/227995 to your computer and use it in GitHub Desktop.
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment