class CancelJobs
include ApplicationHelper
- include DbCurrentTime
def cancel_stale_jobs
act_as_system_user do
Job.running.each do |jobrecord|
f = Log.where("object_uuid=?", jobrecord.uuid).limit(1).order("created_at desc").first
if f
- current_time = db_current_time
- age = (current_time - f.created_at)
+ age = (Time.now - f.created_at)
if age > 300
$stderr.puts "dispatch: failing orphan job #{jobrecord.uuid}, last log is #{age} seconds old"
# job is marked running, but not known to crunch-dispatcher, and
# hasn't produced any log entries for 5 minutes, so mark it as failed.
jobrecord.running = false
- jobrecord.cancelled_at ||= current_time
- jobrecord.finished_at ||= current_time
+ jobrecord.cancelled_at ||= Time.now
+ jobrecord.finished_at ||= Time.now
if jobrecord.success.nil?
jobrecord.success = false
end