application_job.rb 783 B

1234567891011121314151617
  1. class ApplicationJob < ActiveJob::Base
  2. # Automatically retry jobs that encountered a deadlock
  3. # retry_on ActiveRecord::Deadlocked
  4. # Most jobs are safe to ignore if the underlying records are no longer available
  5. # discard_on ActiveJob::DeserializationError
  6. # We (currently) rely on Delayed::Job#attempts to check for stuck backends
  7. # e.g. in the MonitoringController.
  8. # This is a workaround to sync ActiveJob#executions to Delayed::Job#attempts
  9. # until we resolve this dependency.
  10. after_enqueue do |job|
  11. # update the column right away without loading Delayed::Job record
  12. # see: https://stackoverflow.com/a/34264580
  13. Delayed::Job.where(id: job.provider_job_id).update_all(attempts: job.executions) # rubocop:disable Rails/SkipsModelValidations
  14. end
  15. end