diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-12 21:08:59 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-12 21:08:59 +0300 |
commit | 6d533fe8b44007d82b8de29a4b706da69e5f5936 (patch) | |
tree | f02d924a3b8f81ca28852c993831fcf596417f1b /app/workers | |
parent | f44248b613e94534fd6a1b1f8fb6df179f1bbf56 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/all_queues.yml | 8 | ||||
-rw-r--r-- | app/workers/user_status_cleanup/batch_worker.rb | 33 |
2 files changed, 41 insertions, 0 deletions
diff --git a/app/workers/all_queues.yml b/app/workers/all_queues.yml index 485d8eee000..6d4e6de30d9 100644 --- a/app/workers/all_queues.yml +++ b/app/workers/all_queues.yml @@ -467,6 +467,14 @@ :weight: 1 :idempotent: true :tags: [] +- :name: cronjob:user_status_cleanup_batch + :feature_category: :users + :has_external_dependencies: + :urgency: :low + :resource_boundary: :unknown + :weight: 1 + :idempotent: true + :tags: [] - :name: cronjob:users_create_statistics :feature_category: :users :has_external_dependencies: diff --git a/app/workers/user_status_cleanup/batch_worker.rb b/app/workers/user_status_cleanup/batch_worker.rb new file mode 100644 index 00000000000..0c1087cc4d2 --- /dev/null +++ b/app/workers/user_status_cleanup/batch_worker.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +module UserStatusCleanup + # This worker will run every minute to look for user status records to clean up. + class BatchWorker + include ApplicationWorker + # rubocop:disable Scalability/CronWorkerContext + include CronjobQueue + # rubocop:enable Scalability/CronWorkerContext + + feature_category :users + + idempotent! + + # Avoid running too many UPDATE queries at once + MAX_RUNTIME = 30.seconds + + def perform + return unless UserStatus.scheduled_for_cleanup.exists? + + start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) + + loop do + result = Users::BatchStatusCleanerService.execute + break if result[:deleted_rows] < Users::BatchStatusCleanerService::BATCH_SIZE + + current_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) + + break if (current_time - start_time) > MAX_RUNTIME + end + end + end +end |