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:
commit
6a4bb0656d
2 changed files with 17 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue