summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorMichael Kozono <mkozono@gmail.com>2017-09-08 13:10:53 -0700
committerMichael Kozono <mkozono@gmail.com>2017-09-14 14:17:23 -0700
commitee4f73916f586112e6479d80b3769e174414eb7e (patch)
tree260857524c956e31bbb6b6df2a7e7bdbddb46e45 /db
parentdbf924c57dc026747dae00141c1da67fbf856c80 (diff)
downloadgitlab-ce-ee4f73916f586112e6479d80b3769e174414eb7e.tar.gz
Extract helper for queuing background jobs
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20170907170235_delete_conflicting_redirect_routes.rb33
1 files changed, 1 insertions, 32 deletions
diff --git a/db/post_migrate/20170907170235_delete_conflicting_redirect_routes.rb b/db/post_migrate/20170907170235_delete_conflicting_redirect_routes.rb
index 73bb4603eb6..021b52b9ed1 100644
--- a/db/post_migrate/20170907170235_delete_conflicting_redirect_routes.rb
+++ b/db/post_migrate/20170907170235_delete_conflicting_redirect_routes.rb
@@ -5,8 +5,6 @@ class DeleteConflictingRedirectRoutes < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
- BATCH_SIZE = 1000 # Number of rows to process per job
- JOB_BUFFER_SIZE = 1000 # Number of jobs to bulk queue at a time
MIGRATION = 'DeleteConflictingRedirectRoutesRange'.freeze
disable_ddl_transaction!
@@ -18,11 +16,9 @@ class DeleteConflictingRedirectRoutes < ActiveRecord::Migration
end
def up
- jobs = []
-
say opening_message
- queue_background_migration_jobs(Route, MIGRATION)
+ queue_background_migration_jobs_by_range(Route, MIGRATION)
end
def down
@@ -36,31 +32,4 @@ class DeleteConflictingRedirectRoutes < ActiveRecord::Migration
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/13357
MSG
end
-
- def queue_background_migration_jobs(model_class, job_class_name, batch_size = BATCH_SIZE)
- jobs = []
-
- model_class.each_batch(of: batch_size) do |relation|
- start_id, end_id = relation.pluck('MIN(id), MAX(id)').first
-
- # Note: This conditional will only be true if JOB_BUFFER_SIZE * batch_size < (total number of rows)
- if jobs.length >= JOB_BUFFER_SIZE
- # We push multiple jobs at a time to reduce the time spent in
- # Sidekiq/Redis operations. We're using this buffer based approach so we
- # don't need to run additional queries for every range.
- bulk_queue_jobs(jobs)
- jobs.clear
- end
-
- jobs << [job_class_name, [start_id, end_id]]
- end
-
- bulk_queue_jobs(jobs) unless jobs.empty?
- end
-
- def bulk_queue_jobs(jobs)
- say "Queuing #{jobs.size} BackgroundMigrationWorker jobs..."
-
- BackgroundMigrationWorker.perform_bulk(jobs)
- end
end