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.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #elapsed_time ⇒ Object
-
#initialize ⇒ JobContext
constructor
A new instance of JobContext.
- #process_event(ev, *args) ⇒ Object
- #to_hash ⇒ Object
Methods included from Logger
Constructor Details
#initialize ⇒ JobContext
Returns a new instance of JobContext.
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/isono/node_modules/job_worker.rb', line 113 def initialize() super({:job_id=>Util.gen_id, :parent_job_id=>nil, :started_at=>nil, :finished_at=>nil, :finish_status=>nil, }) @run_cb=proc{} @fail_cb=nil @state = :init end |
Instance Attribute Details
#fail_cb ⇒ Object
Returns the value of attribute fail_cb.
110 111 112 |
# File 'lib/isono/node_modules/job_worker.rb', line 110 def fail_cb @fail_cb end |
#run_cb ⇒ Object
Returns the value of attribute run_cb.
110 111 112 |
# File 'lib/isono/node_modules/job_worker.rb', line 110 def run_cb @run_cb end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
111 112 113 |
# File 'lib/isono/node_modules/job_worker.rb', line 111 def state @state end |
Instance Method Details
#elapsed_time ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/isono/node_modules/job_worker.rb', line 152 def elapsed_time if finished_at && started_at finished_at - started_at else 0 end end |
#process_event(ev, *args) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/isono/node_modules/job_worker.rb', line 127 def process_event(ev, *args) case [ev,@state] when [:on_start, :init] @state = :running self.started_at = Time.now logger.info("Job start #{job_id}") when [:on_done, :running] @state = :done self.finished_at = Time.now logger.info("Job complete #{job_id}: #{elapsed_time} sec") when [:on_fail, :running] @state = :failed on_fail(args[0]) when [:on_fail, :init] @state = :failed on_fail(args[0]) else raise "Unknown state transition: #{ev}, #{@state}" end end |
#to_hash ⇒ Object
148 149 150 |
# File 'lib/isono/node_modules/job_worker.rb', line 148 def to_hash @table.dup.merge({:state=>@state}) end |