-
-
Notifications
You must be signed in to change notification settings - Fork 279
/
delete_job_by_digest.lua
58 lines (52 loc) · 1.86 KB
/
delete_job_by_digest.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
local queue = "queue:" .. KEYS[1]
local unique_digest = KEYS[2]
local function delete_from_sorted_set(name, digest)
local per = 50
local total = redis.call('zcard', name)
local index = 0
local result
-- redis.log(redis.LOG_DEBUG, "delete_from_sorted_set("..name..","..digest..")")
while (index < total) do
-- redis.log(redis.LOG_DEBUG, "delete_from_sorted_set("..name..","..digest..") - "..index.."-"..per)
local items = redis.call('ZRANGE', name, index, index + per -1)
for _, item in pairs(items) do
-- redis.log(redis.LOG_DEBUG, "delete_from_sorted_set("..name..","..digest..") - current item: " .. item)
if string.find(item, digest) then
-- redis.log(redis.LOG_DEBUG, "delete_from_sorted_set("..name..","..digest..") - deleting item")
redis.call('ZREM', name, item)
result = item
break
end
end
index = index + per
end
return result
end
local per = 50
local total = redis.call('LLEN', queue)
local index = 0
local result = nil
-- redis.log(redis.LOG_DEBUG, "delete_job_by_digest.lua - looping through: " .. queue)
while (index < total) do
-- redis.log(redis.LOG_DEBUG, "delete_job_by_digest.lua - " .. index .. "-" .. per)
local items = redis.call('LRANGE', queue, index, index + per -1)
for _, item in pairs(items) do
-- redis.log(redis.LOG_DEBUG, "delete_job_by_digest.lua - item: " .. item)
if string.find(item, unique_digest) then
-- redis.log(redis.LOG_DEBUG, "delete_job_by_digest.lua - found item with digest: " .. unique_digest .. " in: " ..queue)
redis.call('LREM', queue, 1, item)
result = item
break
end
end
index = index + per
end
if result then
return result
end
result = delete_from_sorted_set('schedule', unique_digest)
if result then
return result
end
result = delete_from_sorted_set('retry', unique_digest)
return result