diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index d394c3d10..9a41ff518 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -4,4 +4,14 @@ class ApplicationJob < ActiveJob::Base # Most jobs are safe to ignore if the underlying records are no longer available # 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 diff --git a/spec/jobs/application_job_spec.rb b/spec/jobs/application_job_spec.rb new file mode 100644 index 000000000..27b0a5f9d --- /dev/null +++ b/spec/jobs/application_job_spec.rb @@ -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