Class: ProcessBalancer::Worker
- Inherits:
-
Object
- Object
- ProcessBalancer::Worker
- Defined in:
- lib/process_balancer/worker.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#worker_index ⇒ Object
readonly
Returns the value of attribute worker_index.
Instance Method Summary collapse
-
#initialize(pool, worker_index, job_options) ⇒ Worker
constructor
A new instance of Worker.
- #reason ⇒ Object
- #running? ⇒ Boolean
- #stop ⇒ Object
- #stopped? ⇒ Boolean
Constructor Details
#initialize(pool, worker_index, job_options) ⇒ Worker
Returns a new instance of Worker.
12 13 14 15 16 17 18 19 |
# File 'lib/process_balancer/worker.rb', line 12 def initialize(pool, worker_index, ) @pool = pool @worker_index = worker_index = cancellation, @origin = Private::Cancellation.new @reloader = ProcessBalancer.[:reloader] @future = Concurrent::Promises.future_on(@pool, cancellation, &method(:runner)) end |
Instance Attribute Details
#worker_index ⇒ Object (readonly)
Returns the value of attribute worker_index.
10 11 12 |
# File 'lib/process_balancer/worker.rb', line 10 def worker_index @worker_index end |
Instance Method Details
#reason ⇒ Object
34 35 36 |
# File 'lib/process_balancer/worker.rb', line 34 def reason @future.rejected? ? @future.reason : '' end |
#running? ⇒ Boolean
21 22 23 |
# File 'lib/process_balancer/worker.rb', line 21 def running? !@origin.resolved? && !@future.resolved? end |
#stop ⇒ Object
29 30 31 32 |
# File 'lib/process_balancer/worker.rb', line 29 def stop @origin.resolve true end |
#stopped? ⇒ Boolean
25 26 27 |
# File 'lib/process_balancer/worker.rb', line 25 def stopped? @future.resolved? end |