Class: ProcessBalancer::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/process_balancer/worker.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

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, job_options)
  @pool                 = pool
  @worker_index         = worker_index
  @job_options          = job_options
  cancellation, @origin = Private::Cancellation.new
  @reloader             = ProcessBalancer.options[:reloader]
  @future               = Concurrent::Promises.future_on(@pool, cancellation, &method(:runner))
end

Instance Attribute Details

#worker_indexObject (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

#reasonObject



34
35
36
# File 'lib/process_balancer/worker.rb', line 34

def reason
  @future.rejected? ? @future.reason : ''
end

#running?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/process_balancer/worker.rb', line 21

def running?
  !@origin.resolved? && !@future.resolved?
end

#stopObject



29
30
31
32
# File 'lib/process_balancer/worker.rb', line 29

def stop
  @origin.resolve
  true
end

#stopped?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/process_balancer/worker.rb', line 25

def stopped?
  @future.resolved?
end