Class: Cuetip::Worker
- Inherits:
-
Object
- Object
- Cuetip::Worker
- Includes:
- ActiveSupport::Callbacks
- Defined in:
- lib/cuetip/worker.rb
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(group, id, queues) ⇒ Worker
constructor
A new instance of Worker.
- #request_exit! ⇒ Object
- #run ⇒ Object
- #run_once ⇒ Object
Constructor Details
#initialize(group, id, queues) ⇒ Worker
Returns a new instance of Worker.
13 14 15 16 17 |
# File 'lib/cuetip/worker.rb', line 13 def initialize(group, id, queues) @group = group @id = id @queues = queues end |
Instance Attribute Details
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/cuetip/worker.rb', line 7 def status @status end |
Instance Method Details
#request_exit! ⇒ Object
19 20 21 22 |
# File 'lib/cuetip/worker.rb', line 19 def request_exit! @exit_requested = true interrupt_sleep end |
#run ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cuetip/worker.rb', line 24 def run set_status('idle') loop do unless run_once interruptible_sleep(Cuetip.config.polling_interval + rand) end break if @exit_requested end end |
#run_once ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/cuetip/worker.rb', line 35 def run_once set_status('polling') run_callbacks :poll do queued_job = silence do if @queues.any? scope = Cuetip::Models::QueuedJob.from_queues(@queues) else scope = Cuetip::Models::QueuedJob end scope.find_and_lock end if queued_job set_status("executing #{queued_job.job.id}") run_callbacks :execute do queued_job.job.execute end set_status('idle') true else set_status('idle') false end end end |