Class: ResqueAdmin::Scheduler::Lock::Base
- Inherits:
-
Object
- Object
- ResqueAdmin::Scheduler::Lock::Base
- Defined in:
- lib/resque_admin/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 iff we own it.
-
#release! ⇒ Object
Releases the lock.
- #value ⇒ Object
Constructor Details
#initialize(key, options = {}) ⇒ Base
Returns a new instance of Base.
10 11 12 13 14 15 |
# File 'lib/resque_admin/scheduler/lock/base.rb', line 10 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.
7 8 9 |
# File 'lib/resque_admin/scheduler/lock/base.rb', line 7 def key @key end |
#timeout ⇒ Object
Returns the value of attribute timeout.
8 9 10 |
# File 'lib/resque_admin/scheduler/lock/base.rb', line 8 def timeout @timeout end |
Instance Method Details
#acquire! ⇒ Object
Attempts to acquire the lock. Returns true if successfully acquired.
18 19 20 |
# File 'lib/resque_admin/scheduler/lock/base.rb', line 18 def acquire! raise NotImplementedError end |
#locked? ⇒ Boolean
Returns true if you currently hold the lock.
27 28 29 |
# File 'lib/resque_admin/scheduler/lock/base.rb', line 27 def locked? raise NotImplementedError end |
#release ⇒ Object
Releases the lock iff we own it
37 38 39 |
# File 'lib/resque_admin/scheduler/lock/base.rb', line 37 def release locked? && release! end |
#release! ⇒ Object
Releases the lock.
32 33 34 |
# File 'lib/resque_admin/scheduler/lock/base.rb', line 32 def release! ResqueAdmin.redis.del(key) == 1 end |
#value ⇒ Object
22 23 24 |
# File 'lib/resque_admin/scheduler/lock/base.rb', line 22 def value @value ||= [hostname, process_id].join(':') end |