Class: Resque::Scheduler::Lock::Base
- Inherits:
-
Object
- Object
- Resque::Scheduler::Lock::Base
- Defined in:
- lib/resque/scheduler/lock/base.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#acquire! ⇒ Object
Attempts to acquire the lock.
-
#initialize(key, options = {}) ⇒ Base
constructor
A new instance of Base.
-
#locked? ⇒ Boolean
Returns true if you currently hold the lock.
-
#release! ⇒ Object
Releases the lock.
- #value ⇒ Object
Constructor Details
#initialize(key, options = {}) ⇒ Base
Returns a new instance of Base.
8 9 10 11 12 13 |
# File 'lib/resque/scheduler/lock/base.rb', line 8 def initialize(key, = {}) @key = key # 3 minute default timeout @timeout = [:timeout] || 60 * 3 end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/resque/scheduler/lock/base.rb', line 5 def key @key end |
#timeout ⇒ Object
Returns the value of attribute timeout.
6 7 8 |
# File 'lib/resque/scheduler/lock/base.rb', line 6 def timeout @timeout end |
Instance Method Details
#acquire! ⇒ Object
Attempts to acquire the lock. Returns true if successfully acquired.
16 17 18 |
# File 'lib/resque/scheduler/lock/base.rb', line 16 def acquire! fail NotImplementedError end |
#locked? ⇒ Boolean
Returns true if you currently hold the lock.
25 26 27 |
# File 'lib/resque/scheduler/lock/base.rb', line 25 def locked? fail NotImplementedError end |
#release! ⇒ Object
Releases the lock.
30 31 32 |
# File 'lib/resque/scheduler/lock/base.rb', line 30 def release! Resque.redis.del(key) == 1 end |
#value ⇒ Object
20 21 22 |
# File 'lib/resque/scheduler/lock/base.rb', line 20 def value @value ||= [hostname, process_id].join(':') end |