class OnlineMigrations::BackgroundMigrations::Config

Class representing configuration options for background migrations.

Attributes

backtrace_cleaner[RW]

The Active Support backtrace cleaner that will be used to clean the backtrace of a migration job that errors.

@return [ActiveSupport::BacktraceCleaner, nil] the backtrace cleaner to

use when cleaning a job's backtrace. Defaults to `Rails.backtrace_cleaner`
batch_max_attempts[RW]

Maximum number of batch run attempts

When attempts are exhausted, the individual batch is marked as failed. @return [Integer] defaults to 5

batch_pause[RW]

The pause interval between each background migration job’s execution (in seconds) @return [Integer] defaults to 0

batch_size[RW]

The number of rows to process in a single background migration run @return [Integer] defaults to 20_000

error_handler[RW]

The callback to perform when an error occurs in the migration job.

@example

OnlineMigrations.config.backround_migrations.error_handler = ->(error, errored_job) do
  Bugsnag.notify(error) do |notification|
    notification.add_metadata(:background_migration, { name: errored_job.migration_name })
  end
end

@return [Proc] the callback to perform when an error occurs in the migration job

migrations_module[RW]

The module to namespace background migrations in @return [String] defaults to “OnlineMigrations::BackgroundMigrations”

stuck_jobs_timeout[RW]

The number of seconds that must pass before the running job is considered stuck

@return [Integer] defaults to 1 hour

sub_batch_pause_ms[RW]

The number of milliseconds to sleep between each sub_batch execution @return [Integer] defaults to 100 milliseconds

sub_batch_size[RW]

The smaller batches size that the batches will be divided into @return [Integer] defaults to 1000

throttler[R]

Allows to throttle background migrations based on external signal (e.g. database health)

It will be called before each batch run. If throttled, the current run will be retried next time.

@return [Proc]

@example

OnlineMigrations.config.backround_migrations.throttler = -> { DatabaseStatus.unhealthy? }

Public Class Methods

new() click to toggle source
# File lib/online_migrations/background_migrations/config.rb, line 77
def initialize
  @migrations_module = "OnlineMigrations::BackgroundMigrations"
  @batch_size = 20_000
  @sub_batch_size = 1000
  @batch_pause = 0.seconds
  @sub_batch_pause_ms = 100
  @batch_max_attempts = 5
  @throttler = -> { false }
  @stuck_jobs_timeout = 1.hour
  @error_handler = ->(error, errored_job) {}
end

Public Instance Methods

throttler=(value) click to toggle source
# File lib/online_migrations/background_migrations/config.rb, line 89
def throttler=(value)
  unless value.respond_to?(:call)
    raise ArgumentError, "background_migrations throttler must be a callable."
  end

  @throttler = value
end