amelioration(Procedure.procedure_expires_when_termine_enabled): active l'expiration des dossiers terminés sur les procedure ne l'ayant pas activé jusqu'à présent. La cible est de faire ça sur 20 Procedure quotidiennement

This commit is contained in:
Martin 2023-11-09 15:58:15 +01:00 committed by mfo
parent fcb4b20b65
commit 1716a931c5
3 changed files with 35 additions and 0 deletions

View file

@ -0,0 +1,12 @@
class Cron::EnableProcedureExpiresWhenTermineEnabledJob < Cron::CronJob
self.schedule_expression = Expired.schedule_at(self)
discard_on StandardError
def perform(*args)
return if ENV['ENABLE_PROCEDURE_EXPIRES_WHEN_TERMINE_ENABLED_JOB_LIMIT'].blank?
Procedure.where(procedure_expires_when_termine_enabled: false)
.limit(ENV['ENABLE_PROCEDURE_EXPIRES_WHEN_TERMINE_ENABLED_JOB_LIMIT'])
.order(created_at: :desc)
.update_all(procedure_expires_when_termine_enabled: true)
end
end

View file

@ -30,6 +30,8 @@ module Expired
"every day at 11 pm"
when 'Cron::ExpiredDossiersEnConstructionDeletionJob'
"every day at 3 pm"
when 'Cron::EnableProcedureExpiresWhenTermineEnabledJob'
"every day at 2 am"
else
raise 'please, check the schedule to avoid too much email at the same time'
end

View file

@ -0,0 +1,21 @@
require 'rails_helper'
describe Cron::EnableProcedureExpiresWhenTermineEnabledJob, type: :job do
subject { described_class.perform_now }
let!(:procedure) { create(:procedure, procedure_expires_when_termine_enabled: false) }
context 'when env[ENABLE_PROCEDURE_EXPIRES_WHEN_TERMINE_ENABLED_JOB_LIMIT] is present' do
before do
allow(ENV).to receive(:[]).with('ENABLE_PROCEDURE_EXPIRES_WHEN_TERMINE_ENABLED_JOB_LIMIT').and_return(10)
end
it 'performs' do
expect { subject }.to change { procedure.reload.procedure_expires_when_termine_enabled }.from(false).to(true)
end
end
context 'when env[ENABLE_PROCEDURE_EXPIRES_WHEN_TERMINE_ENABLED_JOB_LIMIT] is absent' do
it 'does not perform without limit' do
expect { subject }.not_to change { procedure.reload.procedure_expires_when_termine_enabled }
end
end
end