Module: Circuitry::Locks::Base

Included in:
Memcache, Memory, NOOP, Redis
Defined in:
lib/circuitry/locks/base.rb

Constant Summary collapse

DEFAULT_SOFT_TTL =

5 minutes

(5 * 60).freeze
DEFAULT_HARD_TTL =

24 hours

(24 * 60 * 60).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hard_ttlObject

Returns the value of attribute hard_ttl.



7
8
9
# File 'lib/circuitry/locks/base.rb', line 7

def hard_ttl
  @hard_ttl
end

#soft_ttlObject

Returns the value of attribute soft_ttl.



7
8
9
# File 'lib/circuitry/locks/base.rb', line 7

def soft_ttl
  @soft_ttl
end

Instance Method Details

#hard_lock(id) ⇒ Object



18
19
20
# File 'lib/circuitry/locks/base.rb', line 18

def hard_lock(id)
  lock!(lock_key(id), hard_ttl)
end

#initialize(options = {}) ⇒ Object



9
10
11
12
# 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

#soft_lock(id) ⇒ Object



14
15
16
# File 'lib/circuitry/locks/base.rb', line 14

def soft_lock(id)
  lock(lock_key(id), soft_ttl)
end

#unlock(id) ⇒ Object



22
23
24
# File 'lib/circuitry/locks/base.rb', line 22

def unlock(id)
  unlock!(lock_key(id))
end