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:
authorOswaldo Ferreira <oswaldo@gitlab.com>2018-07-03 23:05:19 +0300
committerOswaldo Ferreira <oswaldo@gitlab.com>2018-07-10 15:43:58 +0300
commite66535e8407ccb8dd229fefdce817902a364f58a (patch)
treec90cbfc48845479074fd508d3a19b88cc594fda9 /lib/gitlab/background_migration
parent80a7be87f82b36c23e273b6a84b5a6bdbffaa947 (diff)
Create a diff deletion worker scheduler to avoid long-running post-migration
Diffstat (limited to 'lib/gitlab/background_migration')
-rw-r--r--lib/gitlab/background_migration/schedule_diff_files_deletion.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/schedule_diff_files_deletion.rb b/lib/gitlab/background_migration/schedule_diff_files_deletion.rb
new file mode 100644
index 00000000000..d944ed90fce
--- /dev/null
+++ b/lib/gitlab/background_migration/schedule_diff_files_deletion.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+# rubocop:disable Metrics/AbcSize
+# rubocop:disable Style/Documentation
+
+module Gitlab
+ module BackgroundMigration
+ class ScheduleDiffFilesDeletion
+ BATCH_SIZE = 5
+ MIGRATION = 'DeleteDiffFiles'
+ DELAY_INTERVAL = 10.minutes
+
+ def perform(diff_ids, scheduler_index)
+ relation = MergeRequestDiff.where(id: diff_ids)
+
+ job_batches = relation.pluck(:id).in_groups_of(BATCH_SIZE, false).map do |ids|
+ ids.map { |id| [MIGRATION, [id]] }
+ end
+
+ job_batches.each_with_index do |jobs, inner_index|
+ # This will give some space between batches of workers.
+ interval = DELAY_INTERVAL * scheduler_index + inner_index.minutes
+
+ # A single `merge_request_diff` can be associated with way too many
+ # `merge_request_diff_files`. It's better to avoid scheduling big
+ # batches and go with 5 at a time.
+ #
+ BackgroundMigrationWorker.bulk_perform_in(interval, jobs)
+ end
+ end
+ end
+ end
+end