diff --git a/app/jobs/cron/expired_users_deletion_job.rb b/app/jobs/cron/expired_users_deletion_job.rb index 351519cc2..3552fd4e9 100644 --- a/app/jobs/cron/expired_users_deletion_job.rb +++ b/app/jobs/cron/expired_users_deletion_job.rb @@ -1,5 +1,6 @@ class Cron::ExpiredUsersDeletionJob < Cron::CronJob self.schedule_expression = Expired.schedule_at(self) + discard_on StandardError def perform(*args) return if ENV['EXPIRE_USER_DELETION_JOB_LIMIT'].blank? diff --git a/spec/jobs/cron/enable_procedure_expires_when_termine_enabled_job_spec.rb b/spec/jobs/cron/enable_procedure_expires_when_termine_enabled_job_spec.rb index 07e6a6664..ead9187e8 100644 --- a/spec/jobs/cron/enable_procedure_expires_when_termine_enabled_job_spec.rb +++ b/spec/jobs/cron/enable_procedure_expires_when_termine_enabled_job_spec.rb @@ -11,6 +11,11 @@ describe Cron::EnableProcedureExpiresWhenTermineEnabledJob, type: :job do it 'performs' do expect { subject }.to change { procedure.reload.procedure_expires_when_termine_enabled }.from(false).to(true) 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 context 'when env[ENABLE_PROCEDURE_EXPIRES_WHEN_TERMINE_ENABLED_JOB_LIMIT] is absent' do diff --git a/spec/jobs/cron/expired_users_deletion_job_spec.rb b/spec/jobs/cron/expired_users_deletion_job_spec.rb index 6434a73a3..870052af7 100644 --- a/spec/jobs/cron/expired_users_deletion_job_spec.rb +++ b/spec/jobs/cron/expired_users_deletion_job_spec.rb @@ -8,6 +8,11 @@ describe Cron::ExpiredUsersDeletionJob do expect(Expired::UsersDeletionService).to receive(:process_expired) subject 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 context 'when env[EXPIRE_USER_DELETION_JOB_LIMIT] is absent' do