demarches-normaliennes/app/jobs/api_entreprise/job.rb

32 lines
910 B
Ruby
Raw Normal View History

2020-06-02 20:13:38 +02:00
class ApiEntreprise::Job < ApplicationJob
2020-09-22 17:14:31 +02:00
queue_as :api_entreprise
retry_on ApiEntreprise::API::ServiceUnavailable,
ApiEntreprise::API::BadGateway,
wait: 1.day
retry_on ApiEntreprise::API::TimedOut, wait: :exponentially_longer
2020-06-02 20:13:38 +02:00
DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS = 5
# If by the time the job runs the Etablissement has been deleted
# (it can happen through EtablissementUpdateJob for instance), ignore the job
discard_on ActiveRecord::RecordNotFound
rescue_from(ApiEntreprise::API::ResourceNotFound) do |exception|
error(self, exception)
end
rescue_from(ApiEntreprise::API::BadFormatRequest) do |exception|
error(self, exception)
end
2020-07-07 16:56:13 +02:00
def error(job, exception)
# override ApplicationJob#error to avoid reporting to sentry
end
2020-06-02 20:13:38 +02:00
def max_attempts
2020-06-16 15:47:24 +02:00
ENV.fetch("MAX_ATTEMPTS_API_ENTREPRISE_JOBS", DEFAULT_MAX_ATTEMPTS_API_ENTREPRISE_JOBS).to_i
2020-06-02 20:13:38 +02:00
end
end