refactor(demarche): make declarative demarche processing syncroneous
This commit is contained in:
parent
78c85ee8c4
commit
ed4d5cb36a
7 changed files with 42 additions and 181 deletions
|
@ -165,6 +165,7 @@ module Users
|
|||
|
||||
if errors.blank?
|
||||
@dossier.passer_en_construction!
|
||||
@dossier.process_declarative!
|
||||
NotificationMailer.send_en_construction_notification(@dossier).deliver_later
|
||||
@dossier.groupe_instructeur.instructeurs.with_instant_email_dossier_notifications.each do |instructeur|
|
||||
DossierMailer.notify_new_dossier_depose_to_instructeur(@dossier, instructeur.email).deliver_later
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
class Cron::DeclarativeProceduresJob < Cron::CronJob
|
||||
self.schedule_expression = "every 1 minute"
|
||||
|
||||
def perform(*args)
|
||||
Procedure.declarative.find_each do |procedure|
|
||||
begin
|
||||
procedure.process_dossiers!
|
||||
rescue => e
|
||||
Sentry.capture_exception(e)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -169,7 +169,7 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
|
||||
event :passer_automatiquement_en_instruction, after: :after_passer_automatiquement_en_instruction do
|
||||
transitions from: :en_construction, to: :en_instruction
|
||||
transitions from: :en_construction, to: :en_instruction, guard: :can_passer_automatiquement_en_instruction?
|
||||
end
|
||||
|
||||
event :repasser_en_construction, after: :after_repasser_en_construction do
|
||||
|
@ -181,7 +181,7 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
|
||||
event :accepter_automatiquement, after: :after_accepter_automatiquement do
|
||||
transitions from: :en_construction, to: :accepte, guard: :can_terminer?
|
||||
transitions from: :en_construction, to: :accepte, guard: :can_accepter_automatiquement?
|
||||
end
|
||||
|
||||
event :refuser, after: :after_refuser do
|
||||
|
@ -526,6 +526,14 @@ class Dossier < ApplicationRecord
|
|||
true
|
||||
end
|
||||
|
||||
def can_accepter_automatiquement?
|
||||
declarative_triggered_at.nil? && can_terminer?
|
||||
end
|
||||
|
||||
def can_passer_automatiquement_en_instruction?
|
||||
declarative_triggered_at.nil?
|
||||
end
|
||||
|
||||
def can_repasser_en_instruction?
|
||||
termine? && !user_deleted?
|
||||
end
|
||||
|
@ -978,6 +986,14 @@ class Dossier < ApplicationRecord
|
|||
log_dossier_operation(instructeur, :classer_sans_suite, self)
|
||||
end
|
||||
|
||||
def process_declarative!
|
||||
if procedure.declarative_accepte? && may_accepter_automatiquement?
|
||||
accepter_automatiquement!
|
||||
elsif procedure.declarative_en_instruction? && may_passer_automatiquement_en_instruction?
|
||||
passer_automatiquement_en_instruction!
|
||||
end
|
||||
end
|
||||
|
||||
def remove_titres_identite!
|
||||
champs_public.filter(&:titre_identite?).map(&:piece_justificative_file).each(&:purge_later)
|
||||
end
|
||||
|
|
|
@ -447,6 +447,10 @@ class Procedure < ApplicationRecord
|
|||
declarative_with_state == Procedure.declarative_with_states.fetch(:accepte)
|
||||
end
|
||||
|
||||
def declarative_en_instruction?
|
||||
declarative_with_state == Procedure.declarative_with_states.fetch(:en_instruction)
|
||||
end
|
||||
|
||||
def self.declarative_attributes_for_select
|
||||
declarative_with_states.map do |state, _|
|
||||
[I18n.t("activerecord.attributes.#{model_name.i18n_key}.declarative_with_state/#{state}"), state]
|
||||
|
@ -635,23 +639,6 @@ class Procedure < ApplicationRecord
|
|||
result
|
||||
end
|
||||
|
||||
def process_dossiers!
|
||||
case declarative_with_state
|
||||
when Procedure.declarative_with_states.fetch(:en_instruction)
|
||||
dossiers
|
||||
.state_en_construction
|
||||
.where(declarative_triggered_at: nil)
|
||||
.find_each(&:passer_automatiquement_en_instruction!)
|
||||
when Procedure.declarative_with_states.fetch(:accepte)
|
||||
dossiers
|
||||
.state_en_construction
|
||||
.where(declarative_triggered_at: nil)
|
||||
.find_each do |dossier|
|
||||
dossier.accepter_automatiquement! if dossier.may_accepter_automatiquement?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def logo_url
|
||||
if logo.attached?
|
||||
Rails.application.routes.url_helpers.url_for(logo)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue