Class: Isono::NodeModules::JobWorker::JobContext
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Isono::NodeModules::JobWorker::JobContext
- Includes:
- Logger
- Defined in:
- lib/isono/node_modules/job_worker.rb
Instance Attribute Summary collapse
-
#fail_cb ⇒ Object
Returns the value of attribute fail_cb.
-
#run_cb ⇒ Object
Returns the value of attribute run_cb.
-
#stm ⇒ Object
readonly
Returns the value of attribute stm.
Instance Method Summary collapse
- #elapsed_time ⇒ Object
-
#initialize ⇒ JobContext
constructor
A new instance of JobContext.
- #state ⇒ Object
- #to_hash ⇒ Object
Methods included from Logger
Constructor Details
#initialize ⇒ JobContext
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_cb ⇒ Object
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_cb ⇒ Object
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 |
#stm ⇒ Object (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_time ⇒ Object
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 |
#state ⇒ Object
134 135 136 |
# File 'lib/isono/node_modules/job_worker.rb', line 134 def state stm.state end |
#to_hash ⇒ Object
138 139 140 |
# File 'lib/isono/node_modules/job_worker.rb', line 138 def to_hash @table.dup.merge({:state=>@stm.state}) end |