Merge pull request #9729 from mfo/US/fix-cron-job-that-expires-users
correctif(users.expires): typos et perf
This commit is contained in:
commit
0203867460
3 changed files with 14 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue