2016-12-22 21:49:31 +01:00
|
|
|
class ApplicationJob < ActiveJob::Base
|
2021-04-29 13:55:43 +02:00
|
|
|
include ActiveJob::RetryOnTransientErrors
|
2020-06-02 20:13:38 +02:00
|
|
|
|
2021-04-29 13:55:43 +02:00
|
|
|
DEFAULT_MAX_ATTEMPTS_JOBS = 25
|
2020-09-02 16:59:54 +02:00
|
|
|
|
2022-10-11 19:18:59 +02:00
|
|
|
attr_writer :request_id
|
2017-10-03 16:31:17 +02:00
|
|
|
|
2023-06-13 16:27:16 +02:00
|
|
|
before_perform do |job|
|
|
|
|
arg = job.arguments.first
|
|
|
|
|
|
|
|
case arg
|
|
|
|
when Dossier
|
|
|
|
Sentry.set_tags(dossier: arg.id, procedure: arg.procedure.id)
|
|
|
|
when Procedure
|
|
|
|
Sentry.set_tags(procedure: arg.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-11 19:18:59 +02:00
|
|
|
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}")
|
2017-10-03 16:31:17 +02:00
|
|
|
end
|
2018-02-22 10:28:24 +01:00
|
|
|
|
|
|
|
def error(job, exception)
|
2021-01-28 14:49:22 +01:00
|
|
|
Sentry.capture_exception(exception)
|
2018-02-22 10:28:24 +01:00
|
|
|
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
|
2022-10-11 19:18:59 +02:00
|
|
|
|
2023-03-08 18:31:34 +01:00
|
|
|
def max_run_time
|
|
|
|
4.hours # decrease run time by default
|
|
|
|
end
|
|
|
|
|
2022-10-11 19:18:59 +02:00
|
|
|
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
|