Class: Resque::One::QueueLocker
- Inherits:
-
Object
- Object
- Resque::One::QueueLocker
- Defined in:
- lib/resque/one/queue_locker.rb
Instance Attribute Summary collapse
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
Instance Method Summary collapse
-
#initialize(redis, queue) ⇒ QueueLocker
constructor
A new instance of QueueLocker.
- #lock(job_info) ⇒ Object
- #locked?(job_info) ⇒ Boolean
- #unlock(job_info) ⇒ Object
- #unlock_all(klass = nil) ⇒ Object
Constructor Details
#initialize(redis, queue) ⇒ QueueLocker
Returns a new instance of QueueLocker.
7 8 9 10 |
# File 'lib/resque/one/queue_locker.rb', line 7 def initialize(redis, queue) @redis = redis @queue = queue end |
Instance Attribute Details
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
5 6 7 |
# File 'lib/resque/one/queue_locker.rb', line 5 def queue @queue end |
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
5 6 7 |
# File 'lib/resque/one/queue_locker.rb', line 5 def redis @redis end |
Instance Method Details
#lock(job_info) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/resque/one/queue_locker.rb', line 16 def lock(job_info) return false if locked? job_info job_key = key_for job_info redis.set job_key, job_info.id redis.expire job_key, Resque::One.lock_ttl if Resque::One.lock_ttl true end |
#locked?(job_info) ⇒ Boolean
12 13 14 |
# File 'lib/resque/one/queue_locker.rb', line 12 def locked?(job_info) !redis.get(key_for(job_info)).nil? end |
#unlock(job_info) ⇒ Object
26 27 28 |
# File 'lib/resque/one/queue_locker.rb', line 26 def unlock(job_info) redis.del key_for(job_info) end |