Module: Resque::Plugins::Locket
- Defined in:
- lib/resque/plugins/locket/locket.rb,
lib/resque/plugins/locket/worker.rb,
lib/resque/plugins/locket/version.rb
Defined Under Namespace
Modules: Worker
Constant Summary collapse
- VERSION =
"0.1.1"
Instance Method Summary collapse
- #heartbeat_frequency ⇒ Object
-
#heartbeat_frequency=(seconds) ⇒ Object
Adjust how often the job will call to redis to extend the job lock.
- #job_lock_duration ⇒ Object
-
#job_lock_duration=(seconds) ⇒ Object
Adjust how long the duration of the lock will be set to.
- #job_lock_key=(job_lock_proc) ⇒ Object
-
#locket! ⇒ Object
Enable locket.
-
#locket_enabled? ⇒ Boolean
Has resque-locket been enabled?.
-
#locketed_queue?(queue) ⇒ Boolean
Check if a queue’s jobs should be unique across workers.
-
#locketed_queues ⇒ Object
List all locketed queues.
-
#locketed_queues=(queues) ⇒ Object
Set which queues jobs should be unique across workers.
-
#remove_queue(queue) ⇒ Object
When a queue is removed, we also need to remove its lock counters and tell locket to stop tracking it.
Instance Method Details
#heartbeat_frequency ⇒ Object
52 53 54 |
# File 'lib/resque/plugins/locket/locket.rb', line 52 def heartbeat_frequency @heartbeat_frequency || 30 end |
#heartbeat_frequency=(seconds) ⇒ Object
Adjust how often the job will call to redis to extend the job lock.
44 45 46 47 48 49 50 |
# File 'lib/resque/plugins/locket/locket.rb', line 44 def heartbeat_frequency=(seconds) if seconds <= 0 raise ArgumentError, "The heartbeat frequency cannot be 0 seconds" end @heartbeat_frequency = seconds end |
#job_lock_duration ⇒ Object
66 67 68 |
# File 'lib/resque/plugins/locket/locket.rb', line 66 def job_lock_duration @job_lock_duration || 35 end |
#job_lock_duration=(seconds) ⇒ Object
Adjust how long the duration of the lock will be set to. The heartbeat should refresh the lock at a rate faster than its expiration.
58 59 60 61 62 63 64 |
# File 'lib/resque/plugins/locket/locket.rb', line 58 def job_lock_duration=(seconds) if !seconds.is_a?(Integer) || seconds <= 0 raise ArgumentError, "The job lock duration must be an integer greater than 0" end @job_lock_duration = seconds end |
#job_lock_key=(job_lock_proc) ⇒ Object
70 71 72 |
# File 'lib/resque/plugins/locket/locket.rb', line 70 def job_lock_key=(job_lock_proc) @job_lock_proc = job_lock_proc end |
#locket! ⇒ Object
Enable locket. Set all queues to be watched, and register the after_fork hook.
30 31 32 33 34 |
# File 'lib/resque/plugins/locket/locket.rb', line 30 def locket! Resque.after_fork { |job| locket_or_requeue(job) } unless locket_enabled? @locket_enabled = true end |
#locket_enabled? ⇒ Boolean
Has resque-locket been enabled?
25 26 27 |
# File 'lib/resque/plugins/locket/locket.rb', line 25 def locket_enabled? @locket_enabled end |
#locketed_queue?(queue) ⇒ Boolean
Check if a queue’s jobs should be unique across workers.
6 7 8 9 10 11 12 |
# File 'lib/resque/plugins/locket/locket.rb', line 6 def locketed_queue?(queue) case when !locket_enabled? then false when locketed_queues.nil? then true else locketed_queues.include?(queue) end end |
#locketed_queues ⇒ Object
List all locketed queues.
15 16 17 |
# File 'lib/resque/plugins/locket/locket.rb', line 15 def locketed_queues @locketed_queues end |
#locketed_queues=(queues) ⇒ Object
Set which queues jobs should be unique across workers.
20 21 22 |
# File 'lib/resque/plugins/locket/locket.rb', line 20 def locketed_queues=(queues) @locketed_queues = queues end |
#remove_queue(queue) ⇒ Object
When a queue is removed, we also need to remove its lock counters and tell locket to stop tracking it.
38 39 40 41 |
# File 'lib/resque/plugins/locket/locket.rb', line 38 def remove_queue(queue) super(queue) redis.hdel("locket:queue_lock_counters", queue) end |