Created
November 6, 2009 14:04
-
-
Save pkieltyka/227995 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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