2018-07-23 08:23:01 +00:00
|
|
|
class ApplicationJob < ActiveJob::Base
|
|
|
|
# Automatically retry jobs that encountered a deadlock
|
|
|
|
# retry_on ActiveRecord::Deadlocked
|
|
|
|
|
|
|
|
# Most jobs are safe to ignore if the underlying records are no longer available
|
|
|
|
# discard_on ActiveJob::DeserializationError
|
2019-01-02 20:53:29 +00:00
|
|
|
|
|
|
|
# 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.
|
2019-07-04 11:16:55 +00:00
|
|
|
after_enqueue do |job|
|
2019-11-13 07:03:47 +00:00
|
|
|
# skip update of `attempts` attribute if job wasn't queued because of ActiveJobLock
|
|
|
|
#(another job with same lock key got queued before this job could be retried)
|
|
|
|
next if job.provider_job_id.blank?
|
|
|
|
|
2019-07-04 11:16:55 +00:00
|
|
|
# update the column right away without loading Delayed::Job record
|
|
|
|
# see: https://stackoverflow.com/a/34264580
|
|
|
|
Delayed::Job.where(id: job.provider_job_id).update_all(attempts: job.executions) # rubocop:disable Rails/SkipsModelValidations
|
2019-01-02 20:53:29 +00:00
|
|
|
end
|
2018-07-23 08:23:01 +00:00
|
|
|
end
|