Skip to content

Instantly share code, notes, and snippets.

@dcb9
Created October 10, 2020 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcb9/920668491bc3f1c1eeee3cd907998af8 to your computer and use it in GitHub Desktop.
Save dcb9/920668491bc3f1c1eeee3cd907998af8 to your computer and use it in GitHub Desktop.
redis.replicate_commands();
local delayBucket = "dq_delay_bucket";
local readyQueuePrefix = "dq_ready_";
while true do
local first = redis.call("ZRANGE", delayBucket, 0, 0, "WITHSCORES");
local currTime = redis.call("TIME");
if first[2] == nil then
break;
end
if currTime[1] < first[2] then
break;
end
local jobID = first[1];
local jobMeta = redis.call("GET", jobID);
if jobMeta == nil then
redis.call("ZREM", delayBucket, jobID);
end
local metaJson = cmsgpack.unpack(jobMeta);
redis.call("RPUSH", readyQueuePrefix .. metaJson.topic, jobID);
redis.call("ZREM", delayBucket, jobID);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment