Class: BackgroundSchemaMigrationWorker
- Inherits:
-
Object
- Object
- BackgroundSchemaMigrationWorker
- Includes:
- Sidekiq::Job
- Defined in:
- app/workers/background_schema_migration_worker.rb
Overview
Worker to run online_migrations' background schema migrations
This worker runs periodically (via Sidekiq-cron or manual scheduling)
to process enqueued background schema migrations like index creation.
The scheduler picks one migration at a time and runs it. Long-running
operations like CREATE INDEX CONCURRENTLY will run in this worker,
not during deploys.
Setup in config/sidekiq_cron.yml:
background_schema_migrations:
cron: "* * * * *" # Every minute
class: BackgroundSchemaMigrationWorker
queue: low_priority
Or enqueue manually:
BackgroundSchemaMigrationWorker.perform_async
Monitor:
OnlineMigrations::BackgroundSchemaMigrations::Migration.all
Instance Method Summary collapse
Instance Method Details
#perform ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/workers/background_schema_migration_worker.rb', line 32 def perform return unless defined?(OnlineMigrations) # Check for pending migrations pending_count = OnlineMigrations::BackgroundSchemaMigrations::Migration.active.count return if pending_count.zero? logger.info "[BackgroundSchemaMigration] Running scheduler (#{pending_count} active migrations)" # Run the scheduler - it picks one migration at a time OnlineMigrations.run_background_schema_migrations # If there are more migrations, re-enqueue to continue remaining = OnlineMigrations::BackgroundSchemaMigrations::Migration.active.count if remaining.positive? logger.info "[BackgroundSchemaMigration] #{remaining} migrations remaining, re-enqueueing" self.class.perform_in(1.minute) else logger.info "[BackgroundSchemaMigration] All migrations complete" end end |