Skip to content

Instantly share code, notes, and snippets.

@plotti
Created June 22, 2012 11:56
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 plotti/2972316 to your computer and use it in GitHub Desktop.
Save plotti/2972316 to your computer and use it in GitHub Desktop.
Delayed Job helper
# 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