Class: RelaxedJob::Worker
- Inherits:
-
Object
- Object
- RelaxedJob::Worker
- Defined in:
- lib/relaxed_job/worker.rb
Constant Summary collapse
- DEFAULT_SLEEP =
5
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Instance Method Summary collapse
-
#initialize(couchrest_url, options = {}) ⇒ Worker
constructor
A new instance of Worker.
- #name ⇒ Object
- #say(text) ⇒ Object
- #start(options = {}) ⇒ Object
Constructor Details
#initialize(couchrest_url, options = {}) ⇒ Worker
Returns a new instance of Worker.
12 13 14 15 |
# File 'lib/relaxed_job/worker.rb', line 12 def initialize(couchrest_url, ={}) @queue = RelaxedJob::Queue.new(couchrest_url) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/relaxed_job/worker.rb', line 10 def @options end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
9 10 11 |
# File 'lib/relaxed_job/worker.rb', line 9 def queue @queue end |
Instance Method Details
#name ⇒ Object
17 18 19 |
# File 'lib/relaxed_job/worker.rb', line 17 def name "testname" end |
#say(text) ⇒ Object
54 55 56 |
# File 'lib/relaxed_job/worker.rb', line 54 def say(text) puts text unless [:quiet] end |
#start(options = {}) ⇒ Object
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 47 48 49 50 51 52 |
# File 'lib/relaxed_job/worker.rb', line 21 def start(={}) say "*** Starting job worker #{queue.worker_name}" trap('TERM') { say 'Exiting...'; $exit = true } trap('INT') { say 'Exiting...'; $exit = true } sleep_for = [:sleep] || DEFAULT_SLEEP loop do result = nil realtime = Benchmark.realtime do result = queue.work sleep sleep_for end count = result.values.inject(0) { |a,v| a+v } break if $exit if count.zero? sleep sleep_for else say "#{count} jobs processed at %.4f j/s, %d failed ..." % [count / realtime, result[:error]] end break if $exit end ensure queue.clear_locks! end |