Commit 2cc62492 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'mmj-delay-all-batches' into 'master'

Ensure delay for all batches of UserRefreshOverUserRangeWorker jobs enqueued

See merge request gitlab-org/gitlab!63026
parents 357b2ccf 9f148b15
......@@ -9,7 +9,12 @@ module AuthorizedProjectUpdate
# 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|
# Since UserRefreshOverUserRangeWorker has set data_consistency to delayed,
# a job enqueued without a delay could fail because the replica could not catch up with the primary.
# To prevent this, we start the index from `1` instead of `0` so as to ensure that
# no UserRefreshOverUserRangeWorker job is enqueued without a delay.
(1..User.maximum(:id)).each_slice(BATCH_SIZE).with_index(1) do |batch, index|
delay = DELAY_INTERVAL * index
AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker.perform_in(delay, *batch.minmax)
end
......
......@@ -17,7 +17,7 @@ RSpec.describe AuthorizedProjectUpdate::PeriodicRecalculateService do
end
it 'calls AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker' do
(1..User.maximum(:id)).each_slice(batch_size).with_index do |batch, index|
(1..User.maximum(:id)).each_slice(batch_size).with_index(1) do |batch, index|
delay = AuthorizedProjectUpdate::PeriodicRecalculateService::DELAY_INTERVAL * index
expect(AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker).to(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment