Class: Travis::Lock::Redis
- Inherits:
-
Object
- Object
- Travis::Lock::Redis
- Defined in:
- lib/travis/lock/redis.rb
Defined Under Namespace
Classes: LockError
Constant Summary collapse
- DEFAULTS =
{ ttl: 5 * 60 * 1000, retries: 5, interval: 0.1, timeout: 0.5 }
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#monitor ⇒ Object
readonly
Returns the value of attribute monitor.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#retried ⇒ Object
readonly
Returns the value of attribute retried.
Class Method Summary collapse
Instance Method Summary collapse
- #exclusive ⇒ Object
-
#initialize(name, config) ⇒ Redis
constructor
A new instance of Redis.
Constructor Details
#initialize(name, config) ⇒ Redis
Returns a new instance of Redis.
32 33 34 35 36 37 |
# File 'lib/travis/lock/redis.rb', line 32 def initialize(name, config) @name = name @config = DEFAULTS.merge(config) @retried = 0 @monitor = Monitor.new end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
30 31 32 |
# File 'lib/travis/lock/redis.rb', line 30 def config @config end |
#monitor ⇒ Object (readonly)
Returns the value of attribute monitor.
30 31 32 |
# File 'lib/travis/lock/redis.rb', line 30 def monitor @monitor end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
30 31 32 |
# File 'lib/travis/lock/redis.rb', line 30 def name @name end |
#retried ⇒ Object (readonly)
Returns the value of attribute retried.
30 31 32 |
# File 'lib/travis/lock/redis.rb', line 30 def retried @retried end |
Class Method Details
.clients ⇒ Object
19 20 21 |
# File 'lib/travis/lock/redis.rb', line 19 def self.clients @clients ||= {} end |
Instance Method Details
#exclusive ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/travis/lock/redis.rb', line 39 def exclusive do client.lock(name, config[:ttl]) do |lock| lock ? yield(lock) : raise(LockError.new(name)) end end end |