Class: Gitlab::Database::Migrations::RunnerBackoff::Communicator
- Inherits:
-
Object
- Object
- Gitlab::Database::Migrations::RunnerBackoff::Communicator
- Defined in:
- lib/gitlab/database/migrations/runner_backoff/communicator.rb
Constant Summary collapse
- EXPIRY =
1.minute
- KEY =
'gitlab/database/migration/runner/backoff'
Class Method Summary collapse
Instance Method Summary collapse
- #execute_with_lock ⇒ Object
-
#initialize(migration, logger: Gitlab::AppLogger) ⇒ Communicator
constructor
A new instance of Communicator.
Constructor Details
#initialize(migration, logger: Gitlab::AppLogger) ⇒ Communicator
Returns a new instance of Communicator.
21 22 23 24 |
# File 'lib/gitlab/database/migrations/runner_backoff/communicator.rb', line 21 def initialize(migration, logger: Gitlab::AppLogger) @migration = migration @logger = logger end |
Class Method Details
.backoff_runner? ⇒ Boolean
15 16 17 18 19 |
# File 'lib/gitlab/database/migrations/runner_backoff/communicator.rb', line 15 def self.backoff_runner? return false if ::Feature.disabled?(:runner_migrations_backoff, type: :ops) Gitlab::ExclusiveLease.new(KEY, timeout: EXPIRY).exists? end |
.execute_with_lock(migration, &block) ⇒ Object
11 12 13 |
# File 'lib/gitlab/database/migrations/runner_backoff/communicator.rb', line 11 def self.execute_with_lock(migration, &block) new(migration).execute_with_lock(&block) end |
Instance Method Details
#execute_with_lock ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/gitlab/database/migrations/runner_backoff/communicator.rb', line 26 def execute_with_lock log(message: 'Executing migration with Runner backoff') set_lock yield if block_given? ensure remove_lock end |