Permalink
Browse files

Add support to pause/unpause queues.

  • Loading branch information...
myronmarston committed Jan 3, 2013
1 parent 0981b97 commit a22961f9dd61450726c9445f981d93611c929389
Showing with 34 additions and 0 deletions.
  1. +18 −0 pause.lua
  2. +4 −0 pop.lua
  3. +12 −0 unpause.lua
View
@@ -0,0 +1,18 @@
+-- This script takes the name of the queue and adds it
+-- to the ql:paused_queues set.
+--
+-- Args:
+-- 1) The queue to pause.
+--
+-- Note: long term, we have discussed adding a rate-limiting
+-- feature to qless-core, which would be more flexible and
+-- could be used for pausing (i.e. pause = set the rate to 0).
+-- For now, this is far simpler, but we should rewrite this
+-- in terms of the rate limiting feature if/when that is added.
+
+local key = 'ql:paused_queues'
+
+for index, queue in ipairs(ARGV) do
+ redis.call('sadd', key, queue)
+end
+
View
@@ -39,6 +39,10 @@ local keys = {}
-- Make sure we this worker to the list of seen workers
redis.call('zadd', 'ql:workers', now, worker)
+if redis.call('sismember', 'ql:paused_queues', queue) == 1 then
+ return {}
+end
+
-- Iterate through all the expired locks and add them to the list
-- of keys that we'll return
for index, jid in ipairs(redis.call('zrangebyscore', key .. '-locks', 0, now, 'LIMIT', 0, count)) do
View
@@ -0,0 +1,12 @@
+-- This script takes the name of the queue and removes it
+-- from the ql:paused_queues set.
+--
+-- Args:
+-- 1) The queue to unpause.
+
+local key = 'ql:paused_queues'
+
+for index, queue in ipairs(ARGV) do
+ redis.call('srem', key, queue)
+end
+

0 comments on commit a22961f

Please sign in to comment.