demarches-normaliennes/app/jobs/application_job.rb

37 lines
788 B
Ruby
Raw Normal View History

2016-12-22 21:49:31 +01:00
class ApplicationJob < ActiveJob::Base
include ActiveJob::RetryOnTransientErrors
2020-06-02 20:13:38 +02:00
DEFAULT_MAX_ATTEMPTS_JOBS = 25
attr_writer :request_id
around_perform do |job, block|
Rails.logger.info("#{job.class.name} started at #{Time.zone.now}")
Current.set(request_id: job.request_id) do
block.call
end
2018-10-25 15:11:12 +02:00
Rails.logger.info("#{job.class.name} ended at #{Time.zone.now}")
end
def error(job, exception)
2021-01-28 14:49:22 +01:00
Sentry.capture_exception(exception)
end
2020-06-02 20:13:38 +02:00
def max_attempts
2020-06-16 15:47:24 +02:00
ENV.fetch("MAX_ATTEMPTS_JOBS", DEFAULT_MAX_ATTEMPTS_JOBS).to_i
2020-06-02 20:13:38 +02:00
end
def request_id
@request_id ||= Current.request_id
end
def serialize
super.merge('request_id' => request_id)
end
def deserialize(job_data)
super
self.request_id = job_data['request_id']
end
2016-12-22 21:49:31 +01:00
end