Add a job to remove discarded dossiers
This commit is contained in:
parent
26b41caca9
commit
c086f6d580
4 changed files with 48 additions and 0 deletions
|
@ -80,6 +80,7 @@ En local, un utilisateur de test est créé automatiquement, avec les identifian
|
||||||
ExpiredDossiersDeletionJob.set(cron: "0 7 * * *").perform_later
|
ExpiredDossiersDeletionJob.set(cron: "0 7 * * *").perform_later
|
||||||
PurgeStaleExportsJob.set(cron: "*/5 * * * *").perform_later
|
PurgeStaleExportsJob.set(cron: "*/5 * * * *").perform_later
|
||||||
NotifyDraftNotSubmittedJob.set(cron: "0 7 * * *").perform_later
|
NotifyDraftNotSubmittedJob.set(cron: "0 7 * * *").perform_later
|
||||||
|
DiscardedDossiersDeletionJob.set(cron: "0 7 * * *").perform_later
|
||||||
|
|
||||||
### Voir les emails envoyés en local
|
### Voir les emails envoyés en local
|
||||||
|
|
||||||
|
|
8
app/jobs/discarded_dossiers_deletion_job.rb
Normal file
8
app/jobs/discarded_dossiers_deletion_job.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
class DiscardedDossiersDeletionJob < ApplicationJob
|
||||||
|
queue_as :cron
|
||||||
|
|
||||||
|
def perform(*args)
|
||||||
|
Dossier.discarded_brouillon_expired.destroy_all
|
||||||
|
Dossier.discarded_en_construction_expired.destroy_all
|
||||||
|
end
|
||||||
|
end
|
|
@ -199,6 +199,21 @@ class Dossier < ApplicationRecord
|
||||||
scope :without_brouillon_expiration_notice_sent, -> { where(brouillon_close_to_expiration_notice_sent_at: nil) }
|
scope :without_brouillon_expiration_notice_sent, -> { where(brouillon_close_to_expiration_notice_sent_at: nil) }
|
||||||
scope :without_en_construction_expiration_notice_sent, -> { where(en_construction_close_to_expiration_notice_sent_at: nil) }
|
scope :without_en_construction_expiration_notice_sent, -> { where(en_construction_close_to_expiration_notice_sent_at: nil) }
|
||||||
|
|
||||||
|
scope :discarded_brouillon_expired, -> do
|
||||||
|
with_discarded
|
||||||
|
.discarded
|
||||||
|
.state_brouillon
|
||||||
|
.where('hidden_at < ?', 1.month.ago)
|
||||||
|
end
|
||||||
|
scope :discarded_en_construction_expired, -> do
|
||||||
|
with_discarded
|
||||||
|
.discarded
|
||||||
|
.state_en_construction
|
||||||
|
.joins(:procedure)
|
||||||
|
.where('dossiers.hidden_at < ?', 1.month.ago)
|
||||||
|
.where(procedures: { hidden_at: nil })
|
||||||
|
end
|
||||||
|
|
||||||
scope :brouillon_near_procedure_closing_date, -> do
|
scope :brouillon_near_procedure_closing_date, -> do
|
||||||
# select users who have submitted dossier for the given 'procedures.id'
|
# select users who have submitted dossier for the given 'procedures.id'
|
||||||
users_who_submitted =
|
users_who_submitted =
|
||||||
|
|
|
@ -1226,4 +1226,28 @@ describe Dossier do
|
||||||
expect(DossierOperationLog.count).to eq(1)
|
expect(DossierOperationLog.count).to eq(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'discarded_brouillon_expired and discarded_en_construction_expired' do
|
||||||
|
before do
|
||||||
|
create(:dossier)
|
||||||
|
create(:dossier, :en_construction)
|
||||||
|
create(:dossier).discard!
|
||||||
|
create(:dossier, :en_construction).discard!
|
||||||
|
|
||||||
|
Timecop.travel(2.months.ago) do
|
||||||
|
create(:dossier).discard!
|
||||||
|
create(:dossier, :en_construction).discard!
|
||||||
|
|
||||||
|
create(:dossier).procedure.hide!
|
||||||
|
create(:dossier, :en_construction).procedure.hide!
|
||||||
|
end
|
||||||
|
Timecop.travel(1.week.ago) do
|
||||||
|
create(:dossier).discard!
|
||||||
|
create(:dossier, :en_construction).discard!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(Dossier.discarded_brouillon_expired.count).to eq(2) }
|
||||||
|
it { expect(Dossier.discarded_en_construction_expired.count).to eq(1) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue