module Circuitry::Locks::Base

Constants

DEFAULT_HARD_TTL
DEFAULT_SOFT_TTL

Attributes

hard_ttl[RW]
soft_ttl[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/circuitry/locks/base.rb, line 9
def initialize(options = {})
  self.soft_ttl = options.fetch(:soft_ttl, DEFAULT_SOFT_TTL)
  self.hard_ttl = options.fetch(:hard_ttl, DEFAULT_HARD_TTL)
end

Public Instance Methods

hard_lock(id) click to toggle source
# File lib/circuitry/locks/base.rb, line 18
def hard_lock(id)
  lock!(lock_key(id), hard_ttl)
end
soft_lock(id) click to toggle source
# File lib/circuitry/locks/base.rb, line 14
def soft_lock(id)
  lock(lock_key(id), soft_ttl)
end
unlock(id) click to toggle source
# File lib/circuitry/locks/base.rb, line 22
def unlock(id)
  unlock!(lock_key(id))
end

Protected Instance Methods

lock(_key, _ttl) click to toggle source
# File lib/circuitry/locks/base.rb, line 28
def lock(_key, _ttl)
  raise NotImplementedError
end
lock!(_key, _ttl) click to toggle source
# File lib/circuitry/locks/base.rb, line 32
def lock!(_key, _ttl)
  raise NotImplementedError
end
unlock!(_key) click to toggle source
# File lib/circuitry/locks/base.rb, line 36
def unlock!(_key)
  raise NotImplementedError
end

Private Instance Methods

lock_key(id) click to toggle source
# File lib/circuitry/locks/base.rb, line 44
def lock_key(id)
  "circuitry:lock:#{id}"
end