As described here hooking into perform_now is not enough to capture all exceptions that happen during execution of a job because retry logic is implemented as a rescue handler, which simply bypasses entire code flow from the perform_now.
It turned out we need to patch retry_job in order to be able to report exceptions on each retry but this is needed only up until Rails 8.0.2 (included). Luckily latest Rails' version of ActiveJob uses ActiveSupport.error.reporter to report an exception before retrying a job, which means we can provide our own error subscriber and no patching will be needed for Rails > 8.0.2 (not released in the moment of writing this but it's in main).
It turned out there's enqueue_retry.active_job that we can simply rely on for this.
As described here hooking into
perform_nowis not enough to capture all exceptions that happen during execution of a job because retry logic is implemented as a rescue handler, which simply bypasses entire code flow from theperform_now.It turned out we need to patchretry_jobin order to be able to report exceptions on each retry but this is needed only up until Rails 8.0.2 (included). Luckily latest Rails' version of ActiveJob usesActiveSupport.error.reporterto report an exception before retrying a job, which means we can provide our own error subscriber and no patching will be needed for Rails > 8.0.2 (not released in the moment of writing this but it's in main).It turned out there's
enqueue_retry.active_jobthat we can simply rely on for this.