Class: Gitlab::Database::BackgroundMigration::BatchedMigrationWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/database/background_migration/batched_migration_wrapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection:, metrics: PrometheusMetrics.new) ⇒ BatchedMigrationWrapper

Returns a new instance of BatchedMigrationWrapper.



7
8
9
10
# File 'lib/gitlab/database/background_migration/batched_migration_wrapper.rb', line 7

def initialize(connection:, metrics: PrometheusMetrics.new)
  @connection = connection
  @metrics = metrics
end

Instance Method Details

#perform(batch_tracking_record) ⇒ Object

Wraps the execution of a batched_background_migration.

Updates the job’s tracking records with the status of the migration when starting and finishing execution, and optionally saves batch_metrics the migration provides, if any are given.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gitlab/database/background_migration/batched_migration_wrapper.rb', line 22

def perform(batch_tracking_record)
  start_tracking_execution(batch_tracking_record)

  execute_batch(batch_tracking_record)

  batch_tracking_record.succeed!
rescue SubBatchTimeoutError => exception
  caused_by = exception.caused_by
  batch_tracking_record.failure!(error: caused_by, from_sub_batch: true)

  raise caused_by
rescue Exception => error # rubocop:disable Lint/RescueException
  batch_tracking_record.failure!(error: error)

  raise
ensure
  metrics.track(batch_tracking_record)
end