From 252b3e4719a78ed4b7ded0ca06ac56117676d0c9 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 3 Nov 2023 09:22:03 +0100 Subject: [PATCH] =?UTF-8?q?tech(expires-user.cron):=20ajoute=20une=20tache?= =?UTF-8?q?=20cron=20[d=C3=A9brayable]=20pour=20faire=20tourner=20la=20tac?= =?UTF-8?q?he=20de=20suppression=20des=20usagers=20inutile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit attention, pour notre instance, avec ma db anonymiser : ``` ExpiredUsersDeletionService.find_expired_user.pluck(:id).size => 1795515 ``` --- app/jobs/cron/expired_users_deletion_job.rb | 8 ++++++++ config/env.example.optional | 5 ++++- .../cron/expired_users_deletion_job_spec.rb | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 app/jobs/cron/expired_users_deletion_job.rb create mode 100644 spec/jobs/cron/expired_users_deletion_job_spec.rb diff --git a/app/jobs/cron/expired_users_deletion_job.rb b/app/jobs/cron/expired_users_deletion_job.rb new file mode 100644 index 000000000..011e86cb7 --- /dev/null +++ b/app/jobs/cron/expired_users_deletion_job.rb @@ -0,0 +1,8 @@ +class Cron::ExpiredUsersDeletionJob < Cron::CronJob + self.schedule_expression = "every day at 11 pm" + + def perform(*args) + return if ENV['EXPIRE_USER_DELETION_JOB_DISABLED'].present? + ExpiredUsersDeletionService.process_expired + end +end diff --git a/config/env.example.optional b/config/env.example.optional index 65fcedbd8..ecf1b639c 100644 --- a/config/env.example.optional +++ b/config/env.example.optional @@ -229,7 +229,7 @@ REDIS_CACHE_URL="" REDIS_CACHE_SSL="enabled" REDIS_CACHE_SSL_VERIFY_NONE="enabled" -# configuration for sidekiq's redis +# configuration for sidekiq's redis # simple mode # that's all you need to do to conf your sidekiq on a local redis REDIS_URL="redis://localhost:6379" @@ -253,3 +253,6 @@ BULK_EMAIL_QUEUE="low_priority" # work in progress about attestation_v2 WEASYPRINT_URL="http://10.33.23.204:5000/pdf" + +# Use this env var to disable the user expiration mechanism +EXPIRE_USER_DELETION_JOB_DISABLED=anything diff --git a/spec/jobs/cron/expired_users_deletion_job_spec.rb b/spec/jobs/cron/expired_users_deletion_job_spec.rb new file mode 100644 index 000000000..4e7667984 --- /dev/null +++ b/spec/jobs/cron/expired_users_deletion_job_spec.rb @@ -0,0 +1,19 @@ +describe Cron::ExpiredUsersDeletionJob do + subject { described_class.perform_now } + + context 'when env[EXPIRE_USER_DELETION_JOB_DISABLED] is present' do + before { expect(ENV).to receive(:[]).with('EXPIRE_USER_DELETION_JOB_DISABLED').and_return('anything') } + + it 'does not call ExpiredUsersDeletionService.process_expired' do + expect(ExpiredUsersDeletionService).not_to receive(:process_expired) + subject + end + end + + context 'when env[EXPIRE_USER_DELETION_JOB_DISABLED] is absent' do + it 'calls ExpiredUsersDeletionService.process_expired' do + expect(ExpiredUsersDeletionService).to receive(:process_expired) + subject + end + end +end