Merge pull request #9797 from demarches-simplifiees/US/fix-reset-expiring-dossiers-job

correctif(ResetExpiringDossiersJob): timeout sur la prod, utilise une requete plus générique mais plus rapide [on ne scope pas aux dossiers ayant ete notifies, on les reset tous car ca timeouté
This commit is contained in:
mfo 2023-12-07 14:08:43 +00:00 committed by GitHub
commit 6a4bb0656d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View file

@ -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

View file

@ -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)