Class: Isono::NodeModules::JobWorker::JobContext

Inherits:
OpenStruct
  • Object
show all
Includes:
Logger
Defined in:
lib/isono/node_modules/job_worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

included, initialize

Constructor Details

#initializeJobContext

Returns a new instance of JobContext.



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/isono/node_modules/job_worker.rb', line 114

def initialize()
  super({:job_id=>Util.gen_id,
          :parent_job_id=>nil,
          :started_at=>nil,
          :finished_at=>nil,
        })

  @run_cb=proc{}
  @fail_cb=nil

  @stm = Statemachine.build {
    startstate :init
    trans :init,   :on_start,  :running, :on_start
    trans :running, :on_done, :done, :on_done
    trans :running, :on_fail, :failed, :on_fail
    trans :init,   :on_fail, :failed, :on_fail
  }
  @stm.context = self
end

Instance Attribute Details

#fail_cbObject

Returns the value of attribute fail_cb.



112
113
114
# File 'lib/isono/node_modules/job_worker.rb', line 112

def fail_cb
  @fail_cb
end

#run_cbObject

Returns the value of attribute run_cb.



112
113
114
# File 'lib/isono/node_modules/job_worker.rb', line 112

def run_cb
  @run_cb
end

#stmObject (readonly)

Returns the value of attribute stm.



111
112
113
# File 'lib/isono/node_modules/job_worker.rb', line 111

def stm
  @stm
end

Instance Method Details

#elapsed_timeObject



142
143
144
145
146
147
148
# File 'lib/isono/node_modules/job_worker.rb', line 142

def elapsed_time
  if finished_at && started_at
    finished_at - started_at
  else
    0
  end
end

#stateObject



134
135
136
# File 'lib/isono/node_modules/job_worker.rb', line 134

def state
  stm.state
end

#to_hashObject



138
139
140
# File 'lib/isono/node_modules/job_worker.rb', line 138

def to_hash
  @table.dup.merge({:state=>@stm.state})
end