Commit d17d9ea6 authored by Nikola Milojevic's avatar Nikola Milojevic

Merge branch 'bvl-sleep-on-inserting-refreshes' into 'master'

Sleep between inserting batches of refreshes

See merge request gitlab-org/gitlab!83622
parents 096ed6fd 106a9f3d
......@@ -28,11 +28,14 @@ namespace :gitlab do
projects = Project.where(id: ids)
Projects::BuildArtifactsSizeRefresh.enqueue_refresh(projects)
# Take a short break to allow replication to catch up
Kernel.sleep(1)
imported += projects.size
missing += ids.size - projects.size
puts "#{imported}/#{project_ids.size} (missing projects: #{missing})"
end
puts 'Done.'.green
puts 'Done.'
else
puts 'Project IDs must be listed in the CSV under the header PROJECT_ID'.red
end
......
......@@ -27,6 +27,7 @@ RSpec.describe 'gitlab:refresh_project_statistics_build_artifacts_size rake task
stub_const("BUILD_ARTIFACTS_SIZE_REFRESH_ENQUEUE_BATCH_SIZE", 2)
stub_request(:get, csv_url).to_return(status: 200, body: csv_body)
allow(Kernel).to receive(:sleep).with(1)
end
context 'when given a list of space-separated IDs through rake argument' do
......@@ -35,6 +36,14 @@ RSpec.describe 'gitlab:refresh_project_statistics_build_artifacts_size rake task
expect(Projects::BuildArtifactsSizeRefresh.all.map(&:project)).to match_array([project_1, project_2, project_3])
end
it 'inserts refreshes in batches with a sleep' do
expect(Projects::BuildArtifactsSizeRefresh).to receive(:enqueue_refresh).with([project_1, project_2]).ordered
expect(Kernel).to receive(:sleep).with(1)
expect(Projects::BuildArtifactsSizeRefresh).to receive(:enqueue_refresh).with([project_3]).ordered
run_rake_task(rake_task, csv_url)
end
end
context 'when CSV has invalid header' do
......
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