Class: Rub2::JobStore
- Inherits:
-
Object
- Object
- Rub2::JobStore
- Defined in:
- lib/rub2.rb
Instance Method Summary collapse
- #all_finish? ⇒ Boolean
- #each_job(&block) ⇒ Object
- #get_job_from_index(index) ⇒ Object
- #init_job(job_id, job_index, max_retry) ⇒ Object
-
#initialize ⇒ JobStore
constructor
A new instance of JobStore.
- #job_count ⇒ Object
- #mark_dead_job(jobs) ⇒ Object
- #select_retry_jobs ⇒ Object
-
#update_exit_code(exit_status) ⇒ Object
exit_status: [ => 1, :exit_code => 1, …].
Constructor Details
#initialize ⇒ JobStore
Returns a new instance of JobStore.
190 191 192 |
# File 'lib/rub2.rb', line 190 def initialize @jobs = nil end |
Instance Method Details
#all_finish? ⇒ Boolean
233 234 235 |
# File 'lib/rub2.rb', line 233 def all_finish? return @jobs.all? {|j| j.finished?} end |
#each_job(&block) ⇒ Object
227 228 229 230 231 |
# File 'lib/rub2.rb', line 227 def each_job(&block) @jobs.each do |job| yield job end end |
#get_job_from_index(index) ⇒ Object
203 204 205 |
# File 'lib/rub2.rb', line 203 def get_job_from_index(index) return @jobs.find {|j| j.array_id == index} end |
#init_job(job_id, job_index, max_retry) ⇒ Object
194 195 196 197 198 199 200 201 |
# File 'lib/rub2.rb', line 194 def init_job(job_id, job_index, max_retry) raise "already initialized" unless @jobs.nil? jobs = [] job_index.each do |index| jobs.push(Job.new(job_id, index, max_retry)) end @jobs = jobs end |
#job_count ⇒ Object
241 242 243 |
# File 'lib/rub2.rb', line 241 def job_count return @jobs.size end |
#mark_dead_job(jobs) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/rub2.rb', line 215 def mark_dead_job(jobs) now = Time.now jobs.each do |job| if job.dead_end?(now) job.set_exit_code(-1) Rub2.putlog("#{job} no response 1min after finished.") else job.set_dead_time(now) end end end |
#select_retry_jobs ⇒ Object
237 238 239 |
# File 'lib/rub2.rb', line 237 def select_retry_jobs return @jobs.select {|job| job.need_retry?} end |
#update_exit_code(exit_status) ⇒ Object
exit_status: [ => 1, :exit_code => 1, …]
208 209 210 211 212 213 |
# File 'lib/rub2.rb', line 208 def update_exit_code(exit_status) exit_status.each do |es| job = get_job_from_index(es[:array_id]) job.set_exit_code(es[:exit_code]) end end |