Class: OnlineMigrations::BackgroundMigrations::Scheduler

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

Overview

Class responsible for scheduling background migrations. It selects runnable background migrations and runs them one step (one batch) at a time. A migration is considered runnable if it is not completed and the time interval between

successive runs has passed.

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_migrations"
end

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.runObject



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

def self.run
  new.run
end

Instance Method Details

#runObject

Runs Scheduler



23
24
25
26
27
28
29
30
# File 'lib/online_migrations/background_migrations/scheduler.rb', line 23

def run
  active_migrations = Migration.runnable.active.queue_order
  runnable_migrations = active_migrations.select(&:interval_elapsed?)

  runnable_migrations.each do |migration|
    run_migration_job(migration)
  end
end