From b0e818f8f106be81f49f0e7cd3db593e75111072 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 5 Dec 2023 17:49:19 +0100 Subject: [PATCH] =?UTF-8?q?correctif(ResetExpiringDossiersJob):=20timeout?= =?UTF-8?q?=20sur=20la=20prod,=20utilise=20une=20requete=20plus=20g=C3=A9n?= =?UTF-8?q?=C3=A9rique=20mais=20plus=20rapide=20[on=20ne=20scope=20pas=20a?= =?UTF-8?q?ux=20dossiers=20ayant=20ete=20notifies,=20on=20les=20reset=20to?= =?UTF-8?q?us=20car=20ca=20timeout=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/reset_expiring_dossiers_job.rb | 16 +++++++++------- app/models/dossier.rb | 8 ++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/jobs/reset_expiring_dossiers_job.rb b/app/jobs/reset_expiring_dossiers_job.rb index 7f4b4d166..6ab941bf3 100644 --- a/app/jobs/reset_expiring_dossiers_job.rb +++ b/app/jobs/reset_expiring_dossiers_job.rb @@ -1,13 +1,15 @@ class ResetExpiringDossiersJob < ApplicationJob def perform(procedure) - procedure.dossiers - .where.not(brouillon_close_to_expiration_notice_sent_at: nil) - .or(Dossier.where.not(en_construction_close_to_expiration_notice_sent_at: nil)) - .or(Dossier.where.not(termine_close_to_expiration_notice_sent_at: nil)) + procedure + .dossiers .in_batches do |relation| - relation.update_all(brouillon_close_to_expiration_notice_sent_at: nil, - en_construction_close_to_expiration_notice_sent_at: nil, - termine_close_to_expiration_notice_sent_at: nil) + relation.each do |dossier| + if dossier.expiration_started? + dossier.update(brouillon_close_to_expiration_notice_sent_at: nil, + en_construction_close_to_expiration_notice_sent_at: nil, + termine_close_to_expiration_notice_sent_at: nil) + end + end end end end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 84b98c6a0..d0827dee6 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -484,6 +484,14 @@ class Dossier < ApplicationRecord end end + def expiration_started? + [ + brouillon_close_to_expiration_notice_sent_at, + en_construction_close_to_expiration_notice_sent_at, + termine_close_to_expiration_notice_sent_at + ].any?(&:present?) + end + def motivation if termine? traitement&.motivation || read_attribute(:motivation)