Class: Delayed::Worker
- Inherits:
-
Object
- Object
- Delayed::Worker
- Defined in:
- lib/dm-delayed-job/worker.rb
Constant Summary collapse
- SLEEP =
5
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Worker
constructor
A new instance of Worker.
- #say(text) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Worker
Returns a new instance of Worker.
12 13 14 15 16 |
# File 'lib/dm-delayed-job/worker.rb', line 12 def initialize(={}) @quiet = [:quiet] Delayed::Job.min_priority = [:min_priority] if .has_key?(:min_priority) Delayed::Job.max_priority = [:max_priority] if .has_key?(:max_priority) end |
Instance Method Details
#say(text) ⇒ Object
48 49 50 51 |
# File 'lib/dm-delayed-job/worker.rb', line 48 def say(text) puts text unless @quiet logger.info text if logger end |
#start ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/dm-delayed-job/worker.rb', line 18 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.inject(0) { |sum, i| sum+= i } 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 |