Class: OnlineMigrations::BackgroundDataMigrations::Scheduler
- Inherits:
-
Object
- Object
- OnlineMigrations::BackgroundDataMigrations::Scheduler
- Defined in:
- lib/online_migrations/background_data_migrations/scheduler.rb
Overview
Class responsible for scheduling background data migrations.
Scheduler should be configured to run periodically, for example, via cron.
Class Method Summary collapse
Instance Method Summary collapse
-
#run(shard: nil, concurrency: 1) ⇒ Object
Runs Scheduler.
Class Method Details
.run(**options) ⇒ Object
27 28 29 |
# File 'lib/online_migrations/background_data_migrations/scheduler.rb', line 27 def self.run(**) new.run(**) end |
Instance Method Details
#run(shard: nil, concurrency: 1) ⇒ Object
Runs Scheduler
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/online_migrations/background_data_migrations/scheduler.rb', line 32 def run(shard: nil, concurrency: 1) relation = Migration.queue_order relation = relation.where(shard: shard) if shard with_lock do running = relation.running enqueued = relation.enqueued # Ensure no more than 'concurrency' migrations are running at the same time. remaining_to_enqueue = concurrency - running.count if remaining_to_enqueue > 0 migrations_to_enqueue = enqueued.limit(remaining_to_enqueue) migrations_to_enqueue.each do |migration| enqueue_migration(migration) end end end true end |