demarches-normaliennes/app/jobs/process_stalled_declarative_dossier_job.rb

24 lines
734 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class ProcessStalledDeclarativeDossierJob < ApplicationJob
2024-09-24 21:24:22 +02:00
queue_as :low
def perform(dossier)
return if dossier.declarative_triggered_at.present?
case dossier.procedure.declarative_with_state
when Procedure.declarative_with_states.fetch(:en_instruction)
if !dossier.en_instruction? && dossier.may_passer_automatiquement_en_instruction?
dossier.passer_automatiquement_en_instruction!
end
when Procedure.declarative_with_states.fetch(:accepte)
if dossier.may_accepter_automatiquement?
dossier.accepter_automatiquement!
end
end
end
def max_attempts
3 # this job is enqueued by a cron, so it's better to not retry too much
end
end