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.



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/isono/node_modules/job_worker.rb', line 125

def initialize()
  job_id = Util.gen_id
  super({:job_id        => job_id,
         :parent_job_id => nil,
         :session_id    => job_id,
         :job_name      => nil,
         :started_at    => nil,
         :finished_at   => nil,
         :finish_status => nil,
        })
  @run_cb=proc{}
  @fail_cb=nil

  @state = :init
end

Instance Attribute Details

#fail_cbObject

Returns the value of attribute fail_cb.



122
123
124
# File 'lib/isono/node_modules/job_worker.rb', line 122

def fail_cb
  @fail_cb
end

#run_cbObject

Returns the value of attribute run_cb.



122
123
124
# File 'lib/isono/node_modules/job_worker.rb', line 122

def run_cb
  @run_cb
end

#stateObject (readonly)

Returns the value of attribute state.



123
124
125
# File 'lib/isono/node_modules/job_worker.rb', line 123

def state
  @state
end

Instance Method Details

#elapsed_timeObject



166
167
168
169
170
171
172
# File 'lib/isono/node_modules/job_worker.rb', line 166

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

#process_event(ev, *args) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/isono/node_modules/job_worker.rb', line 141

def process_event(ev, *args)
  case [ev,@state]
  when [:on_start, :init]
    @state = :running
    self.started_at = Time.now
    logger.info("Job start #{session_id} (Local ID: #{job_id})[ #{job_name} ]")
  when [:on_done, :running]
    @state = :done
    self.finished_at = Time.now
    logger.info("Job complete #{session_id} (Local ID: #{job_id})[ #{job_name} ]: #{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_hashObject



162
163
164
# File 'lib/isono/node_modules/job_worker.rb', line 162

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