class RailsAsyncMigrations::Migration::FireMigration

Attributes

migration[R]

Public Class Methods

new(migration_id) click to toggle source
# File lib/rails_async_migrations/migration/fire_migration.rb, line 7
def initialize(migration_id)
  @migration = AsyncSchemaMigration.find(migration_id)
end

Public Instance Methods

perform() click to toggle source
# File lib/rails_async_migrations/migration/fire_migration.rb, line 11
def perform
  return if done?

  process!
  run_migration
  done!

  check_queue
end

Private Instance Methods

check_queue() click to toggle source
# File lib/rails_async_migrations/migration/fire_migration.rb, line 23
def check_queue
  Workers.new(:check_queue).perform
end
done!() click to toggle source
# File lib/rails_async_migrations/migration/fire_migration.rb, line 45
def done!
  migration.update! state: 'done'
  Tracer.new.verbose "Migration #{migration.id} was correctly processed"
end
done?() click to toggle source
# File lib/rails_async_migrations/migration/fire_migration.rb, line 34
def done?
  if migration.state == 'done'
    Tracer.new.verbose "Migration #{migration.id} is already `done`, cancelling fire"
    return true
  end
end
failed_with!(error) click to toggle source
# File lib/rails_async_migrations/migration/fire_migration.rb, line 50
def failed_with!(error)
  migration.update! state: 'failed'
  Tracer.new.verbose "Migration #{migration.id} failed with exception `#{error}`"
end
process!() click to toggle source
# File lib/rails_async_migrations/migration/fire_migration.rb, line 41
def process!
  migration.update! state: 'processing'
end
run_migration() click to toggle source
# File lib/rails_async_migrations/migration/fire_migration.rb, line 27
def run_migration
  Migration::Run.new(migration.direction, migration.version).perform
rescue Exception => exception
  failed_with! exception
  raise
end