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