Skip to content

Commit

Permalink
Merge pull request #9797 from demarches-simplifiees/US/fix-reset-expi…
Browse files Browse the repository at this point in the history
…ring-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é
  • Loading branch information
mfo authored Dec 7, 2023
2 parents aed65a4 + b0e818f commit 6a4bb06
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
16 changes: 9 additions & 7 deletions app/jobs/reset_expiring_dossiers_job.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions app/models/dossier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,14 @@ def user_email_for(use)
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)
Expand Down

0 comments on commit 6a4bb06

Please sign in to comment.