good_job: `GoodJob.on_thread_error` not called in tests
I have GoodJob (v3.19.4) on Rails (v6.1.7.6) configured to log errors:
Rails.application.configure do
config.good_job = {
on_thread_error: ->(e) { ErrorLogger.log(e.message) },
}
end
That all seems to work fine, but when I try to write a test for it, the test always fails.
require 'rails_helper'
RSpec.describe 'GoodJob' do
let(:job) { ActiveDirectoryIdChangeRequestJob } # This could be any job
let(:error_message) { 'An error has occurred!' }
describe 'when an error occurs during a job' do
it 'logs an error' do
allow(ErrorLogger).to receive(:log)
allow(Person).to receive(:find).and_raise(RuntimeError, error_message)
job.perform_later
expect(ErrorLogger).to have_received(:log).with(error_message)
end
end
end
However, if I do the error logging in ApplicationJob
, the test passes:
class ApplicationJob < ActiveJob::Base
around_perform do |_job, block|
block.call
rescue RuntimeError => e
ErrorLogger.log(e.message)
end
end
That suggests to me that GoodJob.on_thread_error
isn’t being called, but I can’t figure out why not. The documentation says that it won’t be called if there are an infinite number of retries, but in my set up there are no retries. What am I missing?
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Comments: 15 (8 by maintainers)
Here’s my Calendly if we can debug it together: https://calendly.com/bensheldon/office-hours