X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/79a18f2eb4c02212d30462b3c8eb4f989ab750d3..9bc0194676e3f22b41976fefc6146d7dd965d173:/services/api/script/cancel_stale_jobs.rb diff --git a/services/api/script/cancel_stale_jobs.rb b/services/api/script/cancel_stale_jobs.rb index e59e8d793c..4949ec0880 100755 --- a/services/api/script/cancel_stale_jobs.rb +++ b/services/api/script/cancel_stale_jobs.rb @@ -16,22 +16,20 @@ require File.dirname(__FILE__) + '/../config/environment' 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