Class: OnlineMigrations::ConstantLockRetrier

Inherits:
LockRetrier
  • Object
show all
Defined in:
lib/online_migrations/lock_retrier.rb

Overview

LockRetrier implementation that has a constant delay between tries and lock timeout for each try

Examples:

# This will attempt 5 retries with 2 seconds between each unsuccessful try
# and 50ms set as lock timeout for each try:
config.retrier = OnlineMigrations::ConstantLockRetrier.new(attempts: 5, delay: 2.seconds, lock_timeout: 0.05.seconds)

Instance Attribute Summary collapse

Attributes inherited from LockRetrier

#connection

Instance Method Summary collapse

Methods inherited from LockRetrier

#with_lock_retries

Constructor Details

#initialize(attempts:, delay:, lock_timeout: nil) ⇒ ConstantLockRetrier

Create a new ConstantLockRetrier instance

Parameters:

  • attempts (Integer)

    Maximum number of attempts

  • delay (Numeric)

    Sleep time after unsuccessful lock attempt (in seconds)

  • lock_timeout (Numeric, nil) (defaults to: nil)

    Database lock timeout value (in seconds)



146
147
148
149
150
151
# File 'lib/online_migrations/lock_retrier.rb', line 146

def initialize(attempts:, delay:, lock_timeout: nil)
  super()
  @attempts = attempts
  @delay = delay
  @lock_timeout = lock_timeout
end

Instance Attribute Details

#attemptsInteger (readonly)

LockRetrier API implementation

Returns:

  • (Integer)

    Number of retrying attempts

See Also:



138
139
140
# File 'lib/online_migrations/lock_retrier.rb', line 138

def attempts
  @attempts
end

Instance Method Details

#delay(_attempt) ⇒ Numeric

LockRetrier API implementation

Returns:

  • (Numeric)

    Sleep time after unsuccessful lock attempt (in seconds)

See Also:



167
168
169
# File 'lib/online_migrations/lock_retrier.rb', line 167

def delay(_attempt)
  @delay
end

#lock_timeout(_attempt) ⇒ Numeric

LockRetrier API implementation

Returns:

  • (Numeric)

    Database lock timeout value (in seconds)

See Also:



158
159
160
# File 'lib/online_migrations/lock_retrier.rb', line 158

def lock_timeout(_attempt)
  @lock_timeout
end