Created
June 22, 2012 11:56
-
-
Save plotti/2972316 to your computer and use it in GitHub Desktop.
Delayed Job helper
This file contains hidden or 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
# Helper method that is used when creating delayed jobs. | |
def wait_for_jobs(jobname) | |
continue = true | |
while continue | |
found_pending_jobs = 0 | |
Delayed::Job.all.each do |job| | |
if job.handler.include? jobname | |
found_pending_jobs += 1 | |
end | |
if job.attempts >= 4 | |
puts "#{Project.get_remaining_hits}. Deleting job with more than #{job.attempts} attempts." | |
job.delete | |
end | |
end | |
if found_pending_jobs == 0 | |
continue = false | |
end | |
puts "Remaining API hits: #{Project.get_remaining_hits}. Waiting for #{found_pending_jobs} #{jobname} jobs to finish..." | |
sleep(10) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment