Class: DatWorkerPool::WorkerPoolSpy
- Inherits:
-
Object
- Object
- DatWorkerPool::WorkerPoolSpy
- Defined in:
- lib/dat-worker-pool/worker_pool_spy.rb
Instance Attribute Summary collapse
-
#after_work_callbacks ⇒ Object
readonly
Returns the value of attribute after_work_callbacks.
-
#before_work_callbacks ⇒ Object
readonly
Returns the value of attribute before_work_callbacks.
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#max_workers ⇒ Object
readonly
Returns the value of attribute max_workers.
-
#min_workers ⇒ Object
readonly
Returns the value of attribute min_workers.
-
#on_queue_pop_callbacks ⇒ Object
readonly
Returns the value of attribute on_queue_pop_callbacks.
-
#on_queue_push_callbacks ⇒ Object
readonly
Returns the value of attribute on_queue_push_callbacks.
-
#on_worker_error_callbacks ⇒ Object
readonly
Returns the value of attribute on_worker_error_callbacks.
-
#on_worker_shutdown_callbacks ⇒ Object
readonly
Returns the value of attribute on_worker_shutdown_callbacks.
-
#on_worker_sleep_callbacks ⇒ Object
readonly
Returns the value of attribute on_worker_sleep_callbacks.
-
#on_worker_start_callbacks ⇒ Object
readonly
Returns the value of attribute on_worker_start_callbacks.
-
#on_worker_wakeup_callbacks ⇒ Object
readonly
Returns the value of attribute on_worker_wakeup_callbacks.
-
#shutdown_called ⇒ Object
readonly
Returns the value of attribute shutdown_called.
-
#shutdown_timeout ⇒ Object
readonly
Returns the value of attribute shutdown_timeout.
-
#start_called ⇒ Object
readonly
Returns the value of attribute start_called.
-
#work_items ⇒ Object
readonly
Returns the value of attribute work_items.
-
#work_proc ⇒ Object
readonly
Returns the value of attribute work_proc.
-
#worker_available ⇒ Object
Returns the value of attribute worker_available.
Instance Method Summary collapse
- #add_work(work) ⇒ Object
- #after_work(&block) ⇒ Object
- #before_work(&block) ⇒ Object
-
#initialize(min = 0, max = 1, debug = false, &block) ⇒ WorkerPoolSpy
constructor
A new instance of WorkerPoolSpy.
- #on_queue_pop(&block) ⇒ Object
- #on_queue_push(&block) ⇒ Object
- #on_worker_error(&block) ⇒ Object
- #on_worker_shutdown(&block) ⇒ Object
- #on_worker_sleep(&block) ⇒ Object
- #on_worker_start(&block) ⇒ Object
- #on_worker_wakeup(&block) ⇒ Object
- #pop_work ⇒ Object
- #queue_empty? ⇒ Boolean
- #shutdown(timeout = nil) ⇒ Object
- #start ⇒ Object
- #worker_available? ⇒ Boolean
Constructor Details
#initialize(min = 0, max = 1, debug = false, &block) ⇒ WorkerPoolSpy
Returns a new instance of WorkerPoolSpy.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 16 def initialize(min = 0, max = 1, debug = false, &block) @min_workers = min @max_workers = max @debug = debug @work_proc = block @worker_available = false @work_items = [] @start_called = false @shutdown_called = false @shutdown_timeout = nil @on_queue_pop_callbacks = [] @on_queue_push_callbacks = [] @on_worker_error_callbacks = [] @on_worker_start_callbacks = [] @on_worker_shutdown_callbacks = [] @on_worker_sleep_callbacks = [] @on_worker_wakeup_callbacks = [] @before_work_callbacks = [] @after_work_callbacks = [] end |
Instance Attribute Details
#after_work_callbacks ⇒ Object (readonly)
Returns the value of attribute after_work_callbacks.
13 14 15 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 13 def after_work_callbacks @after_work_callbacks end |
#before_work_callbacks ⇒ Object (readonly)
Returns the value of attribute before_work_callbacks.
13 14 15 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 13 def before_work_callbacks @before_work_callbacks end |
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
5 6 7 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 5 def debug @debug end |
#max_workers ⇒ Object (readonly)
Returns the value of attribute max_workers.
5 6 7 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 5 def max_workers @max_workers end |
#min_workers ⇒ Object (readonly)
Returns the value of attribute min_workers.
5 6 7 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 5 def min_workers @min_workers end |
#on_queue_pop_callbacks ⇒ Object (readonly)
Returns the value of attribute on_queue_pop_callbacks.
9 10 11 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 9 def on_queue_pop_callbacks @on_queue_pop_callbacks end |
#on_queue_push_callbacks ⇒ Object (readonly)
Returns the value of attribute on_queue_push_callbacks.
9 10 11 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 9 def on_queue_push_callbacks @on_queue_push_callbacks end |
#on_worker_error_callbacks ⇒ Object (readonly)
Returns the value of attribute on_worker_error_callbacks.
10 11 12 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 10 def on_worker_error_callbacks @on_worker_error_callbacks end |
#on_worker_shutdown_callbacks ⇒ Object (readonly)
Returns the value of attribute on_worker_shutdown_callbacks.
11 12 13 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 11 def on_worker_shutdown_callbacks @on_worker_shutdown_callbacks end |
#on_worker_sleep_callbacks ⇒ Object (readonly)
Returns the value of attribute on_worker_sleep_callbacks.
12 13 14 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 12 def on_worker_sleep_callbacks @on_worker_sleep_callbacks end |
#on_worker_start_callbacks ⇒ Object (readonly)
Returns the value of attribute on_worker_start_callbacks.
11 12 13 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 11 def on_worker_start_callbacks @on_worker_start_callbacks end |
#on_worker_wakeup_callbacks ⇒ Object (readonly)
Returns the value of attribute on_worker_wakeup_callbacks.
12 13 14 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 12 def on_worker_wakeup_callbacks @on_worker_wakeup_callbacks end |
#shutdown_called ⇒ Object (readonly)
Returns the value of attribute shutdown_called.
8 9 10 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 8 def shutdown_called @shutdown_called end |
#shutdown_timeout ⇒ Object (readonly)
Returns the value of attribute shutdown_timeout.
8 9 10 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 8 def shutdown_timeout @shutdown_timeout end |
#start_called ⇒ Object (readonly)
Returns the value of attribute start_called.
7 8 9 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 7 def start_called @start_called end |
#work_items ⇒ Object (readonly)
Returns the value of attribute work_items.
6 7 8 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 6 def work_items @work_items end |
#work_proc ⇒ Object (readonly)
Returns the value of attribute work_proc.
6 7 8 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 6 def work_proc @work_proc end |
#worker_available ⇒ Object
Returns the value of attribute worker_available.
14 15 16 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 14 def worker_available @worker_available end |
Instance Method Details
#add_work(work) ⇒ Object
48 49 50 51 52 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 48 def add_work(work) return unless work @work_items << work @on_queue_push_callbacks.each(&:call) end |
#after_work(&block) ⇒ Object
76 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 76 def after_work(&block); @after_work_callbacks << block; end |
#before_work(&block) ⇒ Object
75 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 75 def before_work(&block); @before_work_callbacks << block; end |
#on_queue_pop(&block) ⇒ Object
68 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 68 def on_queue_pop(&block); @on_queue_pop_callbacks << block; end |
#on_queue_push(&block) ⇒ Object
69 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 69 def on_queue_push(&block); @on_queue_push_callbacks << block; end |
#on_worker_error(&block) ⇒ Object
70 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 70 def on_worker_error(&block); @on_worker_error_callbacks << block; end |
#on_worker_shutdown(&block) ⇒ Object
72 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 72 def on_worker_shutdown(&block); @on_worker_shutdown_callbacks << block; end |
#on_worker_sleep(&block) ⇒ Object
73 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 73 def on_worker_sleep(&block); @on_worker_sleep_callbacks << block; end |
#on_worker_start(&block) ⇒ Object
71 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 71 def on_worker_start(&block); @on_worker_start_callbacks << block; end |
#on_worker_wakeup(&block) ⇒ Object
74 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 74 def on_worker_wakeup(&block); @on_worker_wakeup_callbacks << block; end |
#pop_work ⇒ Object
54 55 56 57 58 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 54 def pop_work work = @work_items.shift @on_queue_pop_callbacks.each(&:call) work end |
#queue_empty? ⇒ Boolean
60 61 62 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 60 def queue_empty? @work_items.empty? end |
#shutdown(timeout = nil) ⇒ Object
43 44 45 46 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 43 def shutdown(timeout = nil) @shutdown_called = true @shutdown_timeout = timeout end |
#start ⇒ Object
39 40 41 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 39 def start @start_called = true end |
#worker_available? ⇒ Boolean
64 65 66 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 64 def worker_available? @worker_available end |