2016-12-22 21:49:31 +01:00
|
|
|
class ApplicationJob < ActiveJob::Base
|
2020-06-02 20:13:38 +02:00
|
|
|
DEFAULT_MAX_ATTEMPTS_JOBS = 25
|
|
|
|
|
2017-10-03 16:31:17 +02:00
|
|
|
before_perform do |job|
|
2018-10-25 15:11:12 +02:00
|
|
|
Rails.logger.info("#{job.class.name} started at #{Time.zone.now}")
|
2017-10-03 16:31:17 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
after_perform do |job|
|
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
|
|
|
|
2020-05-19 10:58:07 +02:00
|
|
|
rescue_from(ApiEntreprise::API::ResourceNotFound) do |exception|
|
|
|
|
error(self, exception)
|
|
|
|
end
|
|
|
|
|
|
|
|
rescue_from(ApiEntreprise::API::BadFormatRequest) do |exception|
|
|
|
|
error(self, exception)
|
|
|
|
end
|
|
|
|
|
2018-02-22 10:28:24 +01:00
|
|
|
def error(job, exception)
|
|
|
|
Raven.capture_exception(exception)
|
|
|
|
end
|
2020-06-02 20:13:38 +02:00
|
|
|
|
|
|
|
def max_attempts
|
|
|
|
ENV["MAX_ATTEMPTS_JOBS"].to_i || DEFAULT_MAX_ATTEMPTS_JOBS
|
|
|
|
end
|
2016-12-22 21:49:31 +01:00
|
|
|
end
|