Sha256: 7e27fcb9e3ffe9cc596124ef3b1d1725c97c2ebf4285c33e28c048aa5bf75468
Contents?: true
Size: 1.22 KB
Versions: 1
Compression:
Stored size: 1.22 KB
Contents
module Delayed class Worker @@sleep_delay = 5 cattr_accessor :sleep_delay cattr_accessor :logger self.logger = if defined?(Merb::Logger) Merb.logger elsif defined?(RAILS_DEFAULT_LOGGER) RAILS_DEFAULT_LOGGER end 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_delay) 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
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
delayed_job-1.8.5 | lib/delayed/worker.rb |