Skip to content

Instantly share code, notes, and snippets.

@albus522
Created August 30, 2010 16:03
Show Gist options
  • Save albus522/557606 to your computer and use it in GitHub Desktop.
Save albus522/557606 to your computer and use it in GitHub Desktop.
worker = Delayed::Worker.new(:min_priority => ENV['MIN_PRIORITY'], :max_priority => ENV['MAX_PRIORITY'])
begin
worker.say "Starting job worker"
trap('TERM') { worker.say 'Exiting...'; $exit = true }
trap('INT') { worker.say 'Exiting...'; $exit = true }
loop do
result = nil
realtime = Benchmark.realtime do
result = worker.work_off
end
count = result.sum
break if $exit
if count.zero?
break
else
worker.say "#{count} jobs processed at %.4f j/s, %d failed ..." % [count / realtime, result.last]
end
break if $exit
end
ensure
Delayed::Job.clear_locks!(worker.name)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment