Class: Travis::Lock::Redis

Inherits:
Object
  • Object
show all
Extended by:
MonitorMixin
Defined in:
lib/travis/lock/redis.rb

Defined Under Namespace

Classes: LockError

Constant Summary collapse

DEFAULTS =
{
  ttl:      5 * 60,
  retries:  5,
  interval: 0.1
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, config) ⇒ Redis

Returns a new instance of Redis.



26
27
28
29
30
# File 'lib/travis/lock/redis.rb', line 26

def initialize(name, config)
  @name    = name
  @config  = DEFAULTS.merge(config)
  @retried = 0
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



24
25
26
# File 'lib/travis/lock/redis.rb', line 24

def config
  @config
end

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/travis/lock/redis.rb', line 24

def name
  @name
end

#retriedObject (readonly)

Returns the value of attribute retried.



24
25
26
# File 'lib/travis/lock/redis.rb', line 24

def retried
  @retried
end

Instance Method Details

#exclusiveObject



32
33
34
35
36
37
38
# File 'lib/travis/lock/redis.rb', line 32

def exclusive
  retrying do
    client.lock(name, config[:ttl]) do |lock|
      lock ? yield : raise(LockError.new(name))
    end
  end
end