Class: OnlineMigrations::ExponentialLockRetrier
- Inherits:
-
LockRetrier
- Object
- LockRetrier
- OnlineMigrations::ExponentialLockRetrier
- Defined in:
- lib/online_migrations/lock_retrier.rb
Overview
‘LockRetrier` implementation that uses exponential delay with jitter between tries and constant lock timeout for each try
Instance Attribute Summary collapse
-
#attempts ⇒ Integer
readonly
LockRetrier API implementation.
Attributes inherited from LockRetrier
Instance Method Summary collapse
-
#delay(attempt) ⇒ Numeric
LockRetrier API implementation.
-
#initialize(attempts:, base_delay:, max_delay:, lock_timeout: nil) ⇒ ExponentialLockRetrier
constructor
Create a new ExponentialLockRetrier instance.
-
#lock_timeout(_attempt) ⇒ Numeric
LockRetrier API implementation.
Methods inherited from LockRetrier
Constructor Details
#initialize(attempts:, base_delay:, max_delay:, lock_timeout: nil) ⇒ ExponentialLockRetrier
Create a new ExponentialLockRetrier instance
197 198 199 200 201 202 203 |
# File 'lib/online_migrations/lock_retrier.rb', line 197 def initialize(attempts:, base_delay:, max_delay:, lock_timeout: nil) super() @attempts = attempts @base_delay = base_delay @max_delay = max_delay @lock_timeout = lock_timeout end |
Instance Attribute Details
#attempts ⇒ Integer (readonly)
LockRetrier API implementation
188 189 190 |
# File 'lib/online_migrations/lock_retrier.rb', line 188 def attempts @attempts end |
Instance Method Details
#delay(attempt) ⇒ Numeric
LockRetrier API implementation
220 221 222 |
# File 'lib/online_migrations/lock_retrier.rb', line 220 def delay(attempt) (rand * [@max_delay, @base_delay * (2**(attempt - 1))].min).ceil end |
#lock_timeout(_attempt) ⇒ Numeric
LockRetrier API implementation
210 211 212 |
# File 'lib/online_migrations/lock_retrier.rb', line 210 def lock_timeout(_attempt) @lock_timeout end |