Permalink
Browse files

Update to support disappearing workers from the list of known and dis…

…played workers.
  • Loading branch information...
1 parent fb2a9c6 commit 1bb407137c102ce947681ad233ab910287018eef Dan Lecocq committed Jun 20, 2012
Showing with 16 additions and 2 deletions.
  1. +2 −1 README.md
  2. +14 −1 workers.lua
View
@@ -386,7 +386,8 @@ configuration options that `qless` is meant to support:
How many seconds to keep jobs after they're completed
1. `heartbeat-<queue name>` --
The heartbeat interval (in seconds) for a particular queue
-
+1. `max-worker-age` --
+ How long before workers are considered disappeared
Internal Redis Structure
View
@@ -34,6 +34,20 @@ end
local now = assert(tonumber(ARGV[1]), 'Workers(): Arg "now" missing or not a number: ' .. (ARGV[1] or 'nil'))
+-- Clean up all the workers' job lists if they're too old. This is determined
+-- by the `max-worker-age` configuration, defaulting to the last day. Seems
+-- like a 'reasonable' default
+local interval = tonumber(
+ redis.call('hget', 'ql:config', 'max-worker-age')) or 86400
+
+local workers = redis.call('zrangebyscore', 'ql:workers', 0, now - interval)
+for index, worker in ipairs(workers) do
+ redis.call('del', 'ql:w:' .. worker .. ':jobs')
+end
+
+-- And now remove them from the list of known workers
+redis.call('zremrangebyscore', 'ql:workers', 0, now - interval)
+
if #ARGV == 1 then
local response = {}
local workers = redis.call('zrevrange', 'ql:workers', 0, -1)
@@ -47,7 +61,6 @@ if #ARGV == 1 then
return cjson.encode(response)
else
local worker = assert(ARGV[2], 'Workers(): Arg "worker" missing.')
- redis.call('exists', worker)
local response = {
jobs = redis.call('zrevrangebyscore', 'ql:w:' .. worker .. ':jobs', now + 8640000, now),
stalled = redis.call('zrevrangebyscore', 'ql:w:' .. worker .. ':jobs', now, 0)

0 comments on commit 1bb4071

Please sign in to comment.