Module: MutexMigrations::Migrator

Defined in:
lib/mutex_migrations/migrator.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#migrateObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mutex_migrations/migrator.rb', line 19

def migrate
  if use_advisory_lock?
    if MutexMigrations.configuration.enabled
      with_mutex_lock { migrate_without_lock }
    else
      with_advisory_lock { migrate_without_lock }
    end
  else
    migrate_without_lock
  end
end

#runObject



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/mutex_migrations/migrator.rb', line 7

def run
  if use_advisory_lock?
    if MutexMigrations.configuration.enabled
      with_mutex_lock { migrate_without_lock }
    else
      with_advisory_lock { run_without_lock }
    end
  else
    run_without_lock
  end
end

#with_mutex_lockObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mutex_migrations/migrator.rb', line 31

def with_mutex_lock
  raise ConcurrentMigrationError unless Semaphore.instance.lock

  load_migrated

  yield
ensure
  unless Semaphore.instance.unlock
    raise ConcurrentMigrationError.new(
      ConcurrentMigrationError::RELEASE_LOCK_FAILED_MESSAGE
    )
  end
end