Moved .restart_failed_jobs to backend and added rspec test.

This commit is contained in:
Rolf Schmidt 2017-09-07 17:34:32 +02:00
parent 80199a61b5
commit 60e7d990ea
3 changed files with 26 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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