refactor(declarative): process dossier in job isolation

This commit is contained in:
Colin Darie 2023-06-13 16:23:40 +02:00
parent 92bdab3de4
commit 17f5fb4a51
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
5 changed files with 160 additions and 134 deletions

View file

@ -0,0 +1,20 @@
class ProcessStalledDeclarativeDossierJob < ApplicationJob
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.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