Module: Database::BatchedBackgroundMigration::SingleDatabaseWorker

Extended by:
ActiveSupport::Concern
Includes:
ApplicationWorker, CronjobQueue, Gitlab::Utils::StrongMemoize
Included in:
CiDatabaseWorker, Database::BatchedBackgroundMigrationWorker
Defined in:
app/workers/database/batched_background_migration/single_database_worker.rb

Constant Summary collapse

LEASE_TIMEOUT_MULTIPLIER =
3
MINIMUM_LEASE_TIMEOUT =
10.minutes.freeze
INTERVAL_VARIANCE =
5.seconds.freeze

Constants included from ApplicationWorker

ApplicationWorker::LOGGING_EXTRA_KEY, ApplicationWorker::SAFE_PUSH_BULK_LIMIT

Constants included from Gitlab::Loggable

Gitlab::Loggable::ANONYMOUS

Constants included from WorkerAttributes

WorkerAttributes::DEFAULT_DATA_CONSISTENCY, WorkerAttributes::DEFAULT_DEFER_DELAY, WorkerAttributes::NAMESPACE_WEIGHTS, WorkerAttributes::VALID_DATA_CONSISTENCIES, WorkerAttributes::VALID_RESOURCE_BOUNDARIES, WorkerAttributes::VALID_URGENCIES

Instance Method Summary collapse

Methods included from Gitlab::Loggable

#build_structured_payload

Methods included from Gitlab::SidekiqVersioning::Worker

#job_version

Methods included from WorkerContext

#with_context

Instance Method Details

#performObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/workers/database/batched_background_migration/single_database_worker.rb', line 40

def perform
  unless base_model
    Sidekiq.logger.info(
      class: self.class.name,
      database: tracking_database,
      message: 'skipping migration execution for unconfigured database')

    return
  end

  if shares_db_config?
    Sidekiq.logger.info(
      class: self.class.name,
      database: tracking_database,
      message: 'skipping migration execution for database that shares database configuration with another database')

    return
  end

  Gitlab::Database::SharedModel.using_connection(base_model.connection) do
    break unless self.class.enabled?

    migrations = Gitlab::Database::BackgroundMigration::BatchedMigration
      .active_migrations_distinct_on_table(connection: base_model.connection, limit: max_running_migrations).to_a

    queue_migrations_for_execution(migrations) if migrations.any?
  end
end