Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 9ba6b08723
Fetching contributors…

Cannot retrieve contributors at this time

51 lines (37 sloc) 1.138 kB
module Delayed
class Worker
SLEEP = 5
cattr_accessor :logger
self.logger = RAILS_DEFAULT_LOGGER if const_defined?(:RAILS_DEFAULT_LOGGER)
def initialize(options={})
@quiet = options[:quiet]
Delayed::Job.min_priority = options[:min_priority] if options.has_key?(:min_priority)
Delayed::Job.max_priority = options[:max_priority] if options.has_key?(:max_priority)
end
def start
say "*** Starting job worker #{Delayed::Job.worker_name}"
trap('TERM') { say 'Exiting...'; $exit = true }
trap('INT') { say 'Exiting...'; $exit = true }
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)
else
say "#{count} jobs processed at %.4f j/s, %d failed ..." % [count / realtime, result.last]
end
break if $exit
end
ensure
Delayed::Job.clear_locks!
end
def say(text)
puts text unless @quiet
logger.info text if logger
end
end
end
Jump to Line
Something went wrong with that request. Please try again.