Class: OnlineMigrations::BackgroundMigrations::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/online_migrations/background_migrations/config.rb

Overview

Class representing configuration options for background migrations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/online_migrations/background_migrations/config.rb', line 81

def initialize
  @migrations_path = "lib"
  @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

Instance Attribute Details

#backtrace_cleanerActiveSupport::BacktraceCleaner?

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

Returns:

  • (ActiveSupport::BacktraceCleaner, nil)

    the backtrace cleaner to use when cleaning a job's backtrace. Defaults to Rails.backtrace_cleaner



66
67
68
# File 'lib/online_migrations/background_migrations/config.rb', line 66

def backtrace_cleaner
  @backtrace_cleaner
end

#batch_max_attemptsInteger

Maximum number of batch run attempts

When attempts are exhausted, the individual batch is marked as failed.

Returns:

  • (Integer)

    defaults to 5



40
41
42
# File 'lib/online_migrations/background_migrations/config.rb', line 40

def batch_max_attempts
  @batch_max_attempts
end

#batch_pauseInteger

The pause interval between each background migration job's execution (in seconds)

Returns:

  • (Integer)

    defaults to 0



28
29
30
# File 'lib/online_migrations/background_migrations/config.rb', line 28

def batch_pause
  @batch_pause
end

#batch_sizeInteger

The number of rows to process in a single background migration run

Returns:

  • (Integer)

    defaults to 20_000



18
19
20
# File 'lib/online_migrations/background_migrations/config.rb', line 18

def batch_size
  @batch_size
end

#error_handlerProc

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

Examples:

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

Returns:

  • (Proc)

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



79
80
81
# File 'lib/online_migrations/background_migrations/config.rb', line 79

def error_handler
  @error_handler
end

#migrations_moduleString

The module in which background migrations will be placed

Returns:

  • (String)

    defaults to "OnlineMigrations::BackgroundMigrations"



13
14
15
# File 'lib/online_migrations/background_migrations/config.rb', line 13

def migrations_module
  @migrations_module
end

#migrations_pathString

The path where generated background migrations will be placed

Returns:

  • (String)

    defaults to "lib"



9
10
11
# File 'lib/online_migrations/background_migrations/config.rb', line 9

def migrations_path
  @migrations_path
end

#stuck_jobs_timeoutInteger

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

Returns:

  • (Integer)

    defaults to 1 hour



58
59
60
# File 'lib/online_migrations/background_migrations/config.rb', line 58

def stuck_jobs_timeout
  @stuck_jobs_timeout
end

#sub_batch_pause_msInteger

The number of milliseconds to sleep between each sub_batch execution

Returns:

  • (Integer)

    defaults to 100 milliseconds



33
34
35
# File 'lib/online_migrations/background_migrations/config.rb', line 33

def sub_batch_pause_ms
  @sub_batch_pause_ms
end

#sub_batch_sizeInteger

The smaller batches size that the batches will be divided into

Returns:

  • (Integer)

    defaults to 1000



23
24
25
# File 'lib/online_migrations/background_migrations/config.rb', line 23

def sub_batch_size
  @sub_batch_size
end

#throttlerProc

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.

Examples:

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

Returns:

  • (Proc)


52
53
54
# File 'lib/online_migrations/background_migrations/config.rb', line 52

def throttler
  @throttler
end