Class: RaceGuard::Distributed::LockControl
- Inherits:
-
Object
- Object
- RaceGuard::Distributed::LockControl
- Defined in:
- lib/race_guard/distributed/runner.rb
Overview
Yields to a long-running block so it can extend TTL while still holding the owner token.
Instance Method Summary collapse
-
#initialize(opts) ⇒ LockControl
constructor
A new instance of LockControl.
-
#renew(extra_ttl = nil) ⇒ Object
rubocop:disable Metrics/MethodLength – emit + store call.
Constructor Details
#initialize(opts) ⇒ LockControl
Returns a new instance of LockControl.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/race_guard/distributed/runner.rb', line 16 def initialize(opts) @store = opts.fetch(:store) @lock_key = opts.fetch(:lock_key) @token = opts.fetch(:token) @ttl = opts.fetch(:ttl) @lock_name = opts.fetch(:lock_name) @resource_digest = opts.fetch(:resource_digest) @caller_line = opts.fetch(:caller_line) @store_class = opts.fetch(:store_class) end |
Instance Method Details
#renew(extra_ttl = nil) ⇒ Object
rubocop:disable Metrics/MethodLength – emit + store call
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/race_guard/distributed/runner.rb', line 29 def renew(extra_ttl = nil) t = (extra_ttl || @ttl).to_i return false unless t.positive? ok = @store.renew(key: @lock_key, token: @token, ttl: t) if ok Runner.emit_lifecycle( event: 'renewed', lock_name: @lock_name, lock_key: @lock_key, resource_digest: @resource_digest, token: @token, ttl: t, caller_line: @caller_line, store_class: @store_class ) end ok end |