Merge pull request #11057 from mfo/US/fix-autoarchive-stalled

ETQ DS, je souhaite ne pas envoyer plus de mail que prévu quand une demarche se clos a une date prévue
This commit is contained in:
mfo 2024-11-18 15:39:28 +00:00 committed by GitHub
commit aeced409ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 62 additions and 19 deletions

View file

@ -0,0 +1,16 @@
# frozen_string_literal: true
class AutoArchiveProcedureDossiersJob < ApplicationJob
def perform(procedure)
procedure
.dossiers
.state_en_construction
.find_each do |d|
begin
d.passer_automatiquement_en_instruction!
rescue StandardError => e
Sentry.capture_exception(e, extra: { procedure_id: procedure.id })
end
end
end
end

View file

@ -2,18 +2,15 @@
class Cron::AutoArchiveProcedureJob < Cron::CronJob
self.schedule_expression = "every 1 minute"
queue_as :critical
def perform(*args)
procedures_to_close.each do |procedure|
# A buggy procedure should NEVER prevent the closing of another procedure
# we therefore exceptionally add a `begin resue` block.
begin
procedure
.dossiers
.state_en_construction
.find_each(&:passer_automatiquement_en_instruction!)
procedure.close!
AutoArchiveProcedureDossiersJob.perform_later(procedure)
rescue StandardError => e
Sentry.capture_exception(e, extra: { procedure_id: procedure.id })
end

View file

@ -0,0 +1,44 @@
# frozen_string_literal: true
RSpec.describe AutoArchiveProcedureDossiersJob, type: :job do
let!(:procedure) { create(:procedure, :published, :with_instructeur) }
let!(:job) { AutoArchiveProcedureDossiersJob.new }
before do
procedure.auto_archive_on = 1.day.ago.to_date
procedure.save(validate: false)
end
subject { job.perform(procedure) }
context "when procedures have auto_archive_on set on yesterday or today" do
let!(:dossier1) { create(:dossier, procedure: procedure) }
let!(:dossier2) { create(:dossier, :en_construction, procedure: procedure) }
let!(:dossier3) { create(:dossier, :en_construction, procedure: procedure) }
let!(:dossier4) { create(:dossier, :en_construction, procedure: procedure) }
let!(:dossier5) { create(:dossier, :en_instruction, procedure: procedure) }
let!(:dossier6) { create(:dossier, :accepte, procedure: procedure) }
let!(:dossier7) { create(:dossier, :refuse, procedure: procedure) }
let!(:dossier8) { create(:dossier, :sans_suite, procedure: procedure) }
let(:last_operation) { dossier2.dossier_operation_logs.last }
before do
subject
[dossier1, dossier2, dossier3, dossier4, dossier5, dossier6, dossier7, dossier8].each(&:reload)
procedure.reload
end
it {
expect(dossier1.state).to eq Dossier.states.fetch(:brouillon)
expect(dossier2.state).to eq Dossier.states.fetch(:en_instruction)
expect(last_operation.operation).to eq('passer_en_instruction')
expect(last_operation.automatic_operation?).to be_truthy
expect(dossier3.state).to eq Dossier.states.fetch(:en_instruction)
expect(dossier4.state).to eq Dossier.states.fetch(:en_instruction)
expect(dossier5.state).to eq Dossier.states.fetch(:en_instruction)
expect(dossier6.state).to eq Dossier.states.fetch(:accepte)
expect(dossier7.state).to eq Dossier.states.fetch(:refuse)
expect(dossier8.state).to eq Dossier.states.fetch(:sans_suite)
}
end
end

View file

@ -46,20 +46,6 @@ RSpec.describe Cron::AutoArchiveProcedureJob, type: :job do
procedure_aujourdhui.reload
end
it {
expect(dossier1.state).to eq Dossier.states.fetch(:brouillon)
expect(dossier2.state).to eq Dossier.states.fetch(:en_instruction)
expect(last_operation.operation).to eq('passer_en_instruction')
expect(last_operation.automatic_operation?).to be_truthy
expect(dossier3.state).to eq Dossier.states.fetch(:en_instruction)
expect(dossier4.state).to eq Dossier.states.fetch(:en_instruction)
expect(dossier5.state).to eq Dossier.states.fetch(:en_instruction)
expect(dossier6.state).to eq Dossier.states.fetch(:accepte)
expect(dossier7.state).to eq Dossier.states.fetch(:refuse)
expect(dossier8.state).to eq Dossier.states.fetch(:sans_suite)
expect(dossier9.state).to eq Dossier.states.fetch(:en_instruction)
}
it {
expect(procedure_hier.close?).to eq true
expect(procedure_aujourdhui.close?).to eq true