amelioration(Cron::ExpiredUsersDeletionJob): ne retente jamais ce job si il crash [pour eviter de se lancer ds une boucle infinie de suppression]

This commit is contained in:
Martin 2023-11-09 18:43:01 +01:00 committed by mfo
parent 5f452a731e
commit 81826e2509
3 changed files with 11 additions and 0 deletions

View file

@ -1,5 +1,6 @@
class Cron::ExpiredUsersDeletionJob < Cron::CronJob class Cron::ExpiredUsersDeletionJob < Cron::CronJob
self.schedule_expression = Expired.schedule_at(self) self.schedule_expression = Expired.schedule_at(self)
discard_on StandardError
def perform(*args) def perform(*args)
return if ENV['EXPIRE_USER_DELETION_JOB_LIMIT'].blank? return if ENV['EXPIRE_USER_DELETION_JOB_LIMIT'].blank?

View file

@ -11,6 +11,11 @@ describe Cron::EnableProcedureExpiresWhenTermineEnabledJob, type: :job do
it 'performs' do it 'performs' do
expect { subject }.to change { procedure.reload.procedure_expires_when_termine_enabled }.from(false).to(true) expect { subject }.to change { procedure.reload.procedure_expires_when_termine_enabled }.from(false).to(true)
end end
it 'fails gracefuly by catching any error (to prevent re-enqueue and sending too much email)' do
expect(Procedure).to receive(:where).and_raise(StandardError)
expect { subject }.not_to raise_error
end
end end
context 'when env[ENABLE_PROCEDURE_EXPIRES_WHEN_TERMINE_ENABLED_JOB_LIMIT] is absent' do context 'when env[ENABLE_PROCEDURE_EXPIRES_WHEN_TERMINE_ENABLED_JOB_LIMIT] is absent' do

View file

@ -8,6 +8,11 @@ describe Cron::ExpiredUsersDeletionJob do
expect(Expired::UsersDeletionService).to receive(:process_expired) expect(Expired::UsersDeletionService).to receive(:process_expired)
subject subject
end end
it 'fails gracefuly by catching any error (to prevent re-enqueue and sending too much email)' do
expect(Expired::UsersDeletionService).to receive(:process_expired).and_raise(StandardError)
expect { subject }.not_to raise_error
end
end end
context 'when env[EXPIRE_USER_DELETION_JOB_LIMIT] is absent' do context 'when env[EXPIRE_USER_DELETION_JOB_LIMIT] is absent' do