- line.chomp!
- if (re = line.match(/#{job_uuid} (\d+) (\S*) (.*)/))
- ignorethis, whjmpid, taskid, message = re.to_a
- if taskid == '' and message == 'start'
- $stderr.puts "dispatch: noticed #{job_uuid} started"
- j[:started] = true
- ActiveRecord::Base.transaction do
- j[:job].reload
- j[:job].update_attributes running: true, started_at: Time.now
- end
- elsif taskid == '' and (re = message.match /^revision (\S+)$/)
- $stderr.puts "dispatch: noticed #{job_uuid} version #{re[1]}"
- ActiveRecord::Base.transaction do
- j[:job].reload
- j[:job].script_version = re[1]
- j[:job].save
- end
- elsif taskid == '' and (re = message.match /^outputkey (\S+)$/)
- $stderr.puts "dispatch: noticed #{job_uuid} output #{re[1]}"
- j[:output] = re[1]
- elsif taskid == '' and (re = message.match /^meta key is (\S+)$/)
- $stderr.puts "dispatch: noticed #{job_uuid} log #{re[1]}"
- j[:log] = re[1]
- ActiveRecord::Base.transaction do
- j[:job].reload
- j[:job].update_attributes log: j[:log]
- end
- elsif taskid.match(/^\d+/) and (re = message.match /^failure /)
- $stderr.puts "dispatch: noticed #{job_uuid} task fail"
- ActiveRecord::Base.transaction do
- j[:job].reload
- j[:job].tasks_summary ||= {}
- j[:job].tasks_summary[:failed] ||= 0
- j[:job].tasks_summary[:failed] += 1
- j[:job].save
- end
- elsif (re = message.match(/^status: (\d+) done, (\d+) running, (\d+) todo/))
- $stderr.puts "dispatch: noticed #{job_uuid} #{message}"
- ActiveRecord::Base.transaction do
- j[:job].reload
- j[:job].tasks_summary ||= {}
- j[:job].tasks_summary[:done] = re[1].to_i
- j[:job].tasks_summary[:running] = re[2].to_i
- j[:job].tasks_summary[:todo] = re[3].to_i
- j[:job].save
- end
- if re[2].to_i == 0 and re[3].to_i == 0
- $stderr.puts "dispatch: noticed #{job_uuid} succeeded"
- j[:success] = true
- end
- end
- end