Skip to content

Commit

Permalink
Small corrections for the included rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Lütke committed Mar 23, 2008
1 parent 8ec934e commit 3e4e1ac
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions tasks/jobs.rake
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
namespace :jobs do


task :work => :environment do

puts "*** Staring job worker #{Delayed::Job.worker_name}"

SLEEP = 5

trap('TERM') { puts 'Exiting...'; $exit = true }
trap('INT') { puts 'Exiting...'; $exit = true }

loop do

count = 0

realtime = Benchmark.realtime do
count = Delayed::Job.work_off
end

loop do
result = nil

realtime = Benchmark.realtime do
result = Delayed::Job.work_off
end

count = result.sum

break if $exit

if count.zero?
sleep(SLEEP)
puts 'Waiting for more jobs...'
else
RAILS_DEFAULT_LOGGER.info "#{count} jobs completed at %.2f j/s ..." % [count / realtime]
status = "#{count} jobs processed at %.4f j/s, %d failed ..." % [count / realtime, result.last]
RAILS_DEFAULT_LOGGER.info status
puts status
end
break if $exit

break if $exit
end
end
end

0 comments on commit 3e4e1ac

Please sign in to comment.