diff --git a/app/controllers/monitoring_controller.rb b/app/controllers/monitoring_controller.rb index 82980318c..aab7f5ccb 100644 --- a/app/controllers/monitoring_controller.rb +++ b/app/controllers/monitoring_controller.rb @@ -183,9 +183,7 @@ curl http://localhost/api/v1/monitoring/status?token=XXX def restart_failed_jobs access_check - Scheduler.where(status: 'error', active: false).each do |scheduler| - scheduler.update(active: true) - end + Scheduler.restart_failed_jobs render json: {}, status: :ok end diff --git a/app/models/scheduler.rb b/app/models/scheduler.rb index f541ece10..a94a777a2 100644 --- a/app/models/scheduler.rb +++ b/app/models/scheduler.rb @@ -267,4 +267,18 @@ class Scheduler < ApplicationModel end + # This function restarts failed jobs to retry them + # + # @example + # Scheduler.restart_failed_jobs + # + # return [true] + def self.restart_failed_jobs + Scheduler.where(status: 'error', active: false).each do |scheduler| + scheduler.update(active: true) + end + + true + end + end diff --git a/spec/models/scheduler_spec.rb b/spec/models/scheduler_spec.rb index 44e0df6b0..087501aca 100644 --- a/spec/models/scheduler_spec.rb +++ b/spec/models/scheduler_spec.rb @@ -26,6 +26,17 @@ RSpec.describe Scheduler do SpecSpace.send(:remove_const, :DelayedJobBackend) end + describe '.restart_failed_jobs' do + + it 'does restart failed jobs' do + job = create(:scheduler, status: 'error', active: false) + described_class.restart_failed_jobs + job.reload + expect(job.active).to be true + end + + end + describe '._start_job' do it 'sets error status/message for failed jobs' do