Refactoring - Delayed::Job to ActiveJob migration: Allow tracking of ActiveJob#executions via Delayed::Job#attempts sync workaround.
This commit is contained in:
parent
50c1cfcb0a
commit
4d0130810f
2 changed files with 28 additions and 0 deletions
|
@ -4,4 +4,14 @@ class ApplicationJob < ActiveJob::Base
|
||||||
|
|
||||||
# Most jobs are safe to ignore if the underlying records are no longer available
|
# Most jobs are safe to ignore if the underlying records are no longer available
|
||||||
# discard_on ActiveJob::DeserializationError
|
# discard_on ActiveJob::DeserializationError
|
||||||
|
|
||||||
|
# We (currently) rely on Delayed::Job#attempts to check for stuck backends
|
||||||
|
# e.g. in the MonitoringController.
|
||||||
|
# This is a workaround to sync ActiveJob#executions to Delayed::Job#attempts
|
||||||
|
# until we resolve this dependency.
|
||||||
|
around_enqueue do |job, block|
|
||||||
|
block.call.tap do |delayed_job|
|
||||||
|
delayed_job.update!(attempts: job.executions)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
18
spec/jobs/application_job_spec.rb
Normal file
18
spec/jobs/application_job_spec.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
class FailingTestJob < ApplicationJob
|
||||||
|
retry_on(StandardError, attempts: 5)
|
||||||
|
|
||||||
|
def perform
|
||||||
|
Rails.logger.debug 'Failing'
|
||||||
|
raise 'Some error...'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
RSpec.describe ApplicationJob, type: :job do
|
||||||
|
|
||||||
|
it 'syncs ActiveJob#executions to Delayed::Job#attempts' do
|
||||||
|
FailingTestJob.perform_later
|
||||||
|
expect { Delayed::Worker.new.work_off }.to change { Delayed::Job.last.attempts }
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue