Class: Resque::One::QueueLocker
- Inherits:
-
Object
- Object
- Resque::One::QueueLocker
- Defined in:
- lib/resque/one/queue_locker.rb
Constant Summary collapse
- PREFIX =
'resque-one'.freeze
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.
9 10 11 12 |
# File 'lib/resque/one/queue_locker.rb', line 9 def initialize(redis, queue) @redis = redis @queue = queue end |
Instance Attribute Details
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
7 8 9 |
# File 'lib/resque/one/queue_locker.rb', line 7 def queue @queue end |
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
7 8 9 |
# File 'lib/resque/one/queue_locker.rb', line 7 def redis @redis end |
Instance Method Details
#lock(job_info) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/resque/one/queue_locker.rb', line 18 def lock(job_info) return false if locked? job_info job_key = key_for job_info redis.set job_key, job_info.id true end |
#locked?(job_info) ⇒ Boolean
14 15 16 |
# File 'lib/resque/one/queue_locker.rb', line 14 def locked?(job_info) redis.keys(key_for(job_info)).any? end |
#unlock(job_info) ⇒ Object
27 28 29 |
# File 'lib/resque/one/queue_locker.rb', line 27 def unlock(job_info) redis.del key_for(job_info) end |
#unlock_all(klass = nil) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/resque/one/queue_locker.rb', line 31 def unlock_all(klass=nil) filter = klass ? "#{queue_key}:#{klass.to_s}:*" : "#{queue_key}:*" redis.keys(filter).each do |key| redis.del key end end |