Class: BmcDaemonLib::WorkerBase

Inherits:
Object
  • Object
show all
Includes:
LoggerHelper
Defined in:
lib/bmc-daemon-lib/worker.rb

Constant Summary collapse

STATUS_STARTING =

Statuses

"starting"
STATUS_READY =
"ready"
STATUS_WORKING =
"working"
STATUS_SLEEPING =
"sleeping"
STATUS_FINISHED =
"finished"
STATUS_CRASHED =
"crashed"
STATUS_TIMEOUT =
"timeout"
STATUS_DOWN =
"down"

Instance Attribute Summary collapse

Attributes included from LoggerHelper

#logger

Instance Method Summary collapse

Constructor Details

#initialize(wid, pool = nil) ⇒ WorkerBase



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bmc-daemon-lib/worker.rb', line 19

def initialize wid, pool = nil
  # Logger
  log_pipe :workers
  @log_worker_status_changes = true

  # Configuration
  @config = {}

  # Set thread context
  Thread.current.thread_variable_set :wid, (@wid = wid)
  Thread.current.thread_variable_set :pool, (@pool = pool)
  Thread.current.thread_variable_set :started_at, Time.now
  worker_status STATUS_STARTING

  # Ask worker to init itself, and return if there are errors
  if worker_init_result = worker_init
    log_warn "aborting: #{worker_init_result.inspect}", @config
  else
    # We're ok, let's start out loop
    start_loop
  end
end

Instance Attribute Details

#poolObject (readonly)

Class options



16
17
18
# File 'lib/bmc-daemon-lib/worker.rb', line 16

def pool
  @pool
end

#widObject (readonly)

Returns the value of attribute wid.



17
18
19
# File 'lib/bmc-daemon-lib/worker.rb', line 17

def wid
  @wid
end