tech(refactor): deplace l'echelonnement des taches cron liés a l'expiration dans un module dédié

This commit is contained in:
Martin 2023-11-07 07:26:29 +01:00 committed by mfo
parent 99529c611d
commit fb238ff7ac
7 changed files with 31 additions and 5 deletions

View file

@ -1,5 +1,5 @@
class Cron::ExpiredDossiersBrouillonDeletionJob < Cron::CronJob class Cron::ExpiredDossiersBrouillonDeletionJob < Cron::CronJob
self.schedule_expression = "every day at 10 pm" self.schedule_expression = Expired.schedule_at(self)
def perform(*args) def perform(*args)
Expired::DossiersDeletionService.new.process_expired_dossiers_brouillon Expired::DossiersDeletionService.new.process_expired_dossiers_brouillon

View file

@ -1,5 +1,5 @@
class Cron::ExpiredDossiersEnConstructionDeletionJob < Cron::CronJob class Cron::ExpiredDossiersEnConstructionDeletionJob < Cron::CronJob
self.schedule_expression = "every day at 3 pm" self.schedule_expression = Expired.schedule_at(self)
def perform(*args) def perform(*args)
Expired::DossiersDeletionService.new.process_expired_dossiers_en_construction Expired::DossiersDeletionService.new.process_expired_dossiers_en_construction

View file

@ -1,5 +1,5 @@
class Cron::ExpiredDossiersTermineDeletionJob < Cron::CronJob class Cron::ExpiredDossiersTermineDeletionJob < Cron::CronJob
self.schedule_expression = "every day at 7 am" self.schedule_expression = Expired.schedule_at(self)
def perform(*args) def perform(*args)
Expired::DossiersDeletionService.new.process_expired_dossiers_termine Expired::DossiersDeletionService.new.process_expired_dossiers_termine

View file

@ -1,5 +1,5 @@
class Cron::ExpiredPrefilledDossiersDeletionJob < Cron::CronJob class Cron::ExpiredPrefilledDossiersDeletionJob < Cron::CronJob
self.schedule_expression = "every day at 3:00" self.schedule_expression = Expired.schedule_at(self)
def perform def perform
Dossier.prefilled.state_brouillon.where(user_id: nil, updated_at: ..5.days.ago).destroy_all Dossier.prefilled.state_brouillon.where(user_id: nil, updated_at: ..5.days.ago).destroy_all

View file

@ -1,5 +1,5 @@
class Cron::ExpiredUsersDeletionJob < Cron::CronJob class Cron::ExpiredUsersDeletionJob < Cron::CronJob
self.schedule_expression = "every day at 11 pm" self.schedule_expression = Expired.schedule_at(self)
def perform(*args) def perform(*args)
return if ENV['EXPIRE_USER_DELETION_JOB_LIMIT'].blank? return if ENV['EXPIRE_USER_DELETION_JOB_LIMIT'].blank?

18
app/services/expired.rb Normal file
View file

@ -0,0 +1,18 @@
module Expired
def self.schedule_at(caller)
case caller.name
when 'Cron::ExpiredPrefilledDossiersDeletionJob'
"every day at 3 am"
when 'Cron::ExpiredDossiersTermineDeletionJob'
"every day at 7 am"
when 'Cron::ExpiredDossiersBrouillonDeletionJob'
"every day at 10 pm"
when 'Cron::ExpiredUsersDeletionJob'
"every day at 11 pm"
when 'Cron::ExpiredDossiersEnConstructionDeletionJob'
"every day at 3 pm"
else
raise 'please, check the schedule to avoid too much email at the same time'
end
end
end

View file

@ -0,0 +1,8 @@
describe 'jobs' do
describe 'schedule' do
subject { Rake::Task['jobs:schedule'].invoke }
it 'runs' do
expect { subject }.not_to raise_error
end
end
end