debian-mirror-gitlab/lib/gitlab/background_migration.rb

53 lines
2 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
module Gitlab
module BackgroundMigration
2022-01-26 12:08:38 +05:30
DEFAULT_TRACKING_DATABASE = Gitlab::Database::MAIN_DATABASE_NAME
2021-12-11 22:18:48 +05:30
def self.coordinator_for_database(database)
2022-01-26 12:08:38 +05:30
JobCoordinator.for_tracking_database(database)
2021-12-11 22:18:48 +05:30
end
2022-01-26 12:08:38 +05:30
def self.queue(database: DEFAULT_TRACKING_DATABASE)
2021-12-11 22:18:48 +05:30
coordinator_for_database(database).queue
2017-09-10 17:25:29 +05:30
end
# Begins stealing jobs from the background migrations queue, blocking the
# caller until all jobs have been completed.
#
2020-11-24 15:15:51 +05:30
# When a migration raises a StandardError it is going to retry up to
2017-09-10 17:25:29 +05:30
# three times, for example, to recover from a deadlock.
#
# When Exception is being raised, it enqueues the migration again, and
# re-raises the exception.
#
# steal_class - The name of the class for which to steal jobs.
2021-12-11 22:18:48 +05:30
# retry_dead_jobs - Flag to control whether jobs in Sidekiq::RetrySet or Sidekiq::DeadSet are retried.
# database - tracking database this migration executes against
2022-01-26 12:08:38 +05:30
def self.steal(steal_class, retry_dead_jobs: false, database: DEFAULT_TRACKING_DATABASE, &block)
2021-12-11 22:18:48 +05:30
coordinator_for_database(database).steal(steal_class, retry_dead_jobs: retry_dead_jobs, &block)
2017-09-10 17:25:29 +05:30
end
##
# Performs a background migration.
#
# class_name - The name of the background migration class as defined in the
# Gitlab::BackgroundMigration namespace.
#
# arguments - The arguments to pass to the background migration's "perform"
# method.
2021-12-11 22:18:48 +05:30
# database - tracking database this migration executes against
2022-01-26 12:08:38 +05:30
def self.perform(class_name, arguments, database: DEFAULT_TRACKING_DATABASE)
2021-12-11 22:18:48 +05:30
coordinator_for_database(database).perform(class_name, arguments)
2019-07-31 22:56:46 +05:30
end
2022-01-26 12:08:38 +05:30
def self.exists?(migration_class, additional_queues = [], database: DEFAULT_TRACKING_DATABASE)
2021-12-11 22:18:48 +05:30
coordinator_for_database(database).exists?(migration_class, additional_queues) # rubocop:disable CodeReuse/ActiveRecord
2019-07-31 22:56:46 +05:30
end
2022-01-26 12:08:38 +05:30
def self.remaining(database: DEFAULT_TRACKING_DATABASE)
2021-12-11 22:18:48 +05:30
coordinator_for_database(database).remaining
2019-03-02 22:35:43 +05:30
end
2017-09-10 17:25:29 +05:30
end
end