From b5a44ee0d0b822b3277aa8aee4dc9bf72ca15806 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Mon, 3 Dec 2018 12:27:51 +0100 Subject: [PATCH] Refactoring: Make Scheduler more robust against job deletion while processing. --- app/models/scheduler.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/models/scheduler.rb b/app/models/scheduler.rb index 5710d400d..369c5d923 100644 --- a/app/models/scheduler.rb +++ b/app/models/scheduler.rb @@ -257,13 +257,20 @@ class Scheduler < ApplicationModel else _start_job(job) end - job.pid = '' - job.save - logger.info " ...stopped thread for '#{job.method}'" - ActiveRecord::Base.connection.close - # release thread lock and remove thread handle - @@jobs_started.delete(job.id) + if job.present? + job.pid = '' + job.save + + logger.info " ...stopped thread for '#{job.method}'" + + # release thread lock and remove thread handle + @@jobs_started.delete(job.id) + else + logger.warn ' ...Job got deleted while running' + end + + ActiveRecord::Base.connection.close end end