40 lines
857 B
Ruby
40 lines
857 B
Ruby
class ApplicationJob < ActiveJob::Base
|
|
include ActiveJob::RetryOnTransientErrors
|
|
|
|
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
|
|
Rails.logger.info("#{job.class.name} ended at #{Time.zone.now}")
|
|
end
|
|
|
|
def error(job, exception)
|
|
Sentry.capture_exception(exception)
|
|
end
|
|
|
|
def max_attempts
|
|
ENV.fetch("MAX_ATTEMPTS_JOBS", DEFAULT_MAX_ATTEMPTS_JOBS).to_i
|
|
end
|
|
|
|
def max_run_time
|
|
4.hours # decrease run time by default
|
|
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
|
|
end
|