Class: DatWorkerPool::Worker
- Inherits:
-
Object
- Object
- DatWorkerPool::Worker
- Defined in:
- lib/dat-worker-pool/worker.rb
Instance Attribute Summary collapse
-
#after_work_callbacks ⇒ Object
Returns the value of attribute after_work_callbacks.
-
#before_work_callbacks ⇒ Object
Returns the value of attribute before_work_callbacks.
-
#on_error_callbacks ⇒ Object
Returns the value of attribute on_error_callbacks.
-
#on_shutdown_callbacks ⇒ Object
Returns the value of attribute on_shutdown_callbacks.
-
#on_sleep_callbacks ⇒ Object
Returns the value of attribute on_sleep_callbacks.
-
#on_start_callbacks ⇒ Object
Returns the value of attribute on_start_callbacks.
-
#on_wakeup_callbacks ⇒ Object
Returns the value of attribute on_wakeup_callbacks.
-
#on_work ⇒ Object
Returns the value of attribute on_work.
Instance Method Summary collapse
-
#initialize(queue) ⇒ Worker
constructor
A new instance of Worker.
- #join(*args) ⇒ Object
- #raise(*args) ⇒ Object
- #running? ⇒ Boolean
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(queue) ⇒ Worker
Returns a new instance of Worker.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dat-worker-pool/worker.rb', line 13 def initialize(queue) @queue = queue @on_work = proc{ |worker, work_item| } @on_error_callbacks = [] @on_start_callbacks = [] @on_shutdown_callbacks = [] @on_sleep_callbacks = [] @on_wakeup_callbacks = [] @before_work_callbacks = [] @after_work_callbacks = [] @shutdown = false @thread = nil end |
Instance Attribute Details
#after_work_callbacks ⇒ Object
Returns the value of attribute after_work_callbacks.
11 12 13 |
# File 'lib/dat-worker-pool/worker.rb', line 11 def after_work_callbacks @after_work_callbacks end |
#before_work_callbacks ⇒ Object
Returns the value of attribute before_work_callbacks.
11 12 13 |
# File 'lib/dat-worker-pool/worker.rb', line 11 def before_work_callbacks @before_work_callbacks end |
#on_error_callbacks ⇒ Object
Returns the value of attribute on_error_callbacks.
8 9 10 |
# File 'lib/dat-worker-pool/worker.rb', line 8 def on_error_callbacks @on_error_callbacks end |
#on_shutdown_callbacks ⇒ Object
Returns the value of attribute on_shutdown_callbacks.
9 10 11 |
# File 'lib/dat-worker-pool/worker.rb', line 9 def on_shutdown_callbacks @on_shutdown_callbacks end |
#on_sleep_callbacks ⇒ Object
Returns the value of attribute on_sleep_callbacks.
10 11 12 |
# File 'lib/dat-worker-pool/worker.rb', line 10 def on_sleep_callbacks @on_sleep_callbacks end |
#on_start_callbacks ⇒ Object
Returns the value of attribute on_start_callbacks.
9 10 11 |
# File 'lib/dat-worker-pool/worker.rb', line 9 def on_start_callbacks @on_start_callbacks end |
#on_wakeup_callbacks ⇒ Object
Returns the value of attribute on_wakeup_callbacks.
10 11 12 |
# File 'lib/dat-worker-pool/worker.rb', line 10 def on_wakeup_callbacks @on_wakeup_callbacks end |
#on_work ⇒ Object
Returns the value of attribute on_work.
8 9 10 |
# File 'lib/dat-worker-pool/worker.rb', line 8 def on_work @on_work end |
Instance Method Details
#join(*args) ⇒ Object
40 41 42 |
# File 'lib/dat-worker-pool/worker.rb', line 40 def join(*args) @thread.join(*args) if running? end |
#raise(*args) ⇒ Object
44 45 46 |
# File 'lib/dat-worker-pool/worker.rb', line 44 def raise(*args) @thread.raise(*args) if running? end |
#running? ⇒ Boolean
36 37 38 |
# File 'lib/dat-worker-pool/worker.rb', line 36 def running? !!(@thread && @thread.alive?) end |
#shutdown ⇒ Object
32 33 34 |
# File 'lib/dat-worker-pool/worker.rb', line 32 def shutdown @shutdown = true end |
#start ⇒ Object
28 29 30 |
# File 'lib/dat-worker-pool/worker.rb', line 28 def start @thread ||= Thread.new{ work_loop } end |