Refactoring - Delayed::Job to ActiveJob migration: Allow tracking of ActiveJob#executions via Delayed::Job#attempts sync workaround.

This commit is contained in:
Thorsten Eckel 2019-01-02 21:53:29 +01:00
parent 50c1cfcb0a
commit 4d0130810f
2 changed files with 28 additions and 0 deletions

View file

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

View 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