Class: AuthorizedProjectUpdate::PeriodicRecalculateService

Inherits:
Object
  • Object
show all
Defined in:
app/services/authorized_project_update/periodic_recalculate_service.rb

Constant Summary collapse

BATCH_SIZE =
480
DELAY_INTERVAL =
30.seconds.to_i

Instance Method Summary collapse

Instance Method Details

#executeObject


8
9
10
11
12
13
14
15
16
# File 'app/services/authorized_project_update/periodic_recalculate_service.rb', line 8

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