Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--[[ | ||
Remove all jobs matching a given pattern from all the queues they may be in as well as all its data. | ||
In order to be able to remove any job, they must be unlocked. | ||
Input: | ||
KEYS[1] 'active', | ||
KEYS[2] 'wait', | ||
KEYS[3] 'delayed', | ||
KEYS[4] 'paused', | ||
KEYS[5] 'completed', | ||
KEYS[6] 'failed', | ||
KEYS[7] 'priority', | ||
ARGV[1] prefix | ||
ARGV[2] pattern | ||
ARGV[3] cursor | ||
Events: | ||
'removed' | ||
]] | ||
|
||
-- TODO PUBLISH global events 'removed' | ||
|
||
local rcall = redis.call | ||
local result = rcall("SCAN", ARGV[3], "MATCH", ARGV[1] .. ARGV[2]) | ||
local cursor = result[1]; | ||
local jobKeys = result[2]; | ||
local removed = {} | ||
|
||
local prefixLen = string.len(ARGV[1]) + 1 | ||
for i, jobKey in ipairs(jobKeys) do | ||
local keyTypeResp = rcall("TYPE", jobKey) | ||
if keyTypeResp["ok"] == "hash" then | ||
local jobId = string.sub(jobKey, prefixLen) | ||
local lockKey = jobKey .. ':lock' | ||
local lock = redis.call("GET", lockKey) | ||
if not lock then | ||
rcall("LREM", KEYS[1], 0, jobId) | ||
rcall("LREM", KEYS[2], 0, jobId) | ||
rcall("ZREM", KEYS[3], jobId) | ||
rcall("LREM", KEYS[4], 0, jobId) | ||
rcall("ZREM", KEYS[5], jobId) | ||
rcall("ZREM", KEYS[6], jobId) | ||
rcall("ZREM", KEYS[7], jobId) | ||
rcall("DEL", jobKey) | ||
rcall("DEL", jobKey .. ':logs') | ||
table.insert(removed, jobId) | ||
end | ||
end | ||
end | ||
return {cursor, removed} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters