Merge pull request #9729 from mfo/US/fix-cron-job-that-expires-users

correctif(users.expires): typos et perf
This commit is contained in:
mfo 2023-11-21 14:46:14 +00:00 committed by GitHub
commit 0203867460
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 6 deletions

View file

@ -4,6 +4,6 @@ class Cron::ExpiredUsersDeletionJob < Cron::CronJob
def perform(*args)
return if ENV['EXPIRE_USER_DELETION_JOB_LIMIT'].blank?
Expired::UsersDeletionService.process_expired
Expired::UsersDeletionService.new.process_expired
end
end

View file

@ -32,10 +32,18 @@ class Expired::UsersDeletionService < Expired::MailRateLimiter
# rubocop:disable DS/Unscoped
def expired_users_with_dossiers
dossiers = Dossier.arel_table
users = User.arel_table
expired_users
.joins(:dossiers)
.joins(
users.join(dossiers, Arel::Nodes::OuterJoin)
.on(users[:id].eq(dossiers[:user_id])
.and(dossiers[:state].eq(Dossier.states.fetch(:en_instruction))))
.join_sources
)
.where(dossiers[:id].eq(nil))
.group("users.id")
.having("NOT 'en_instruction' = ANY(ARRAY_AGG(dossiers.state))")
end
def expired_users_without_dossiers

View file

@ -5,19 +5,19 @@ describe Cron::ExpiredUsersDeletionJob do
before { expect(ENV).to receive(:[]).with('EXPIRE_USER_DELETION_JOB_LIMIT').and_return('anything') }
it 'calls Expired::UsersDeletionService.process_expired' do
expect(Expired::UsersDeletionService).to receive(:process_expired)
expect_any_instance_of(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_any_instance_of(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
it 'does not call Expired::UsersDeletionService.process_expired' do
expect(Expired::UsersDeletionService).not_to receive(:process_expired)
expect_any_instance_of(Expired::UsersDeletionService).not_to receive(:process_expired)
subject
end
end