Add DiscardedProceduresDeletionJob job
This commit is contained in:
parent
da52ec30bd
commit
58c126308c
4 changed files with 17 additions and 3 deletions
10
app/jobs/discarded_procedures_deletion_job.rb
Normal file
10
app/jobs/discarded_procedures_deletion_job.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
class DiscardedProceduresDeletionJob < CronJob
|
||||
self.cron_expression = "0 7 * * *"
|
||||
|
||||
def perform(*args)
|
||||
Procedure.discarded_expired.find_each do |procedure|
|
||||
procedure.dossiers.with_discarded.destroy_all
|
||||
procedure.destroy
|
||||
end
|
||||
end
|
||||
end
|
|
@ -212,9 +212,7 @@ class Dossier < ApplicationRecord
|
|||
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
|
||||
|
|
|
@ -53,6 +53,12 @@ class Procedure < ApplicationRecord
|
|||
scope :cloned_from_library, -> { where(cloned_from_library: true) }
|
||||
scope :declarative, -> { where.not(declarative_with_state: nil) }
|
||||
|
||||
scope :discarded_expired, -> do
|
||||
with_discarded
|
||||
.discarded
|
||||
.where('hidden_at < ?', 1.month.ago)
|
||||
end
|
||||
|
||||
scope :for_api, -> {
|
||||
includes(
|
||||
:administrateurs,
|
||||
|
|
|
@ -1248,6 +1248,6 @@ describe Dossier do
|
|||
end
|
||||
|
||||
it { expect(Dossier.discarded_brouillon_expired.count).to eq(2) }
|
||||
it { expect(Dossier.discarded_en_construction_expired.count).to eq(1) }
|
||||
it { expect(Dossier.discarded_en_construction_expired.count).to eq(2) }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue