Class: OnlineMigrations::BackgroundSchemaMigrations::Scheduler

Inherits:
Object
  • Object
show all
Defined in:
lib/online_migrations/background_schema_migrations/scheduler.rb

Overview

Class responsible for scheduling background schema migrations. It selects a single migration and runs it if there is no currently running migration on the same table.

Scheduler should be configured to run periodically, for example, via cron.

Examples:

Run via whenever

# add this to schedule.rb
every 1.minute do
  runner "OnlineMigrations.run_background_schema_migrations"
end

Run via whenever (specific shard)

every 1.minute do
  runner "OnlineMigrations.run_background_schema_migrations(shard: :shard_two)"
end

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(**options) ⇒ Object



23
24
25
# File 'lib/online_migrations/background_schema_migrations/scheduler.rb', line 23

def self.run(**options)
  new.run(**options)
end

Instance Method Details

#run(**options) ⇒ Object

Runs Scheduler



28
29
30
31
32
33
34
# File 'lib/online_migrations/background_schema_migrations/scheduler.rb', line 28

def run(**options)
  migration = find_migration(**options)
  if migration
    runner = MigrationRunner.new(migration)
    runner.run
  end
end