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

periodic_recalculate_service.rb « authorized_project_update « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 91c0f50e5e0fcb7ad3fb643404710af8367e2fb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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