Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/authorized_project_update/periodic_recalculate_service.rb')
-rw-r--r--app/services/authorized_project_update/periodic_recalculate_service.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/app/services/authorized_project_update/periodic_recalculate_service.rb b/app/services/authorized_project_update/periodic_recalculate_service.rb
new file mode 100644
index 00000000000..91c0f50e5e0
--- /dev/null
+++ b/app/services/authorized_project_update/periodic_recalculate_service.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+module AuthorizedProjectUpdate
+ class PeriodicRecalculateService
+ BATCH_SIZE = 480
+ DELAY_INTERVAL = 30.seconds.to_i
+
+ def execute
+ # Using this approach (instead of eg. User.each_batch) keeps the arguments
+ # the same for AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker
+ # even if the user list changes, so we can deduplicate these jobs.
+ (1..User.maximum(:id)).each_slice(BATCH_SIZE).with_index do |batch, index|
+ delay = DELAY_INTERVAL * index
+ AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker.perform_in(delay, *batch.minmax)
+ end
+ end
+ end
+end