bullmq 6.3.12 → 6.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ --[[
2
+ Function to move a retried child back to its parent's dependencies.
3
+ This does not move a parent that has already left waiting-children back to that state.
4
+ ]]
5
+ local function moveChildBackToParentDependencies(jobKey, prevState)
6
+ local parentKey = rcall("HGET", jobKey, "parentKey")
7
+
8
+ if parentKey and rcall("EXISTS", parentKey) == 1 then
9
+ if prevState == "failed" then
10
+ if rcall("ZREM", parentKey .. ":unsuccessful", jobKey) == 1 or
11
+ rcall("HDEL", parentKey .. ":failed", jobKey) == 1 then
12
+ rcall("SADD", parentKey .. ":dependencies", jobKey)
13
+ end
14
+ else
15
+ if rcall("HDEL", parentKey .. ":processed", jobKey) == 1 then
16
+ rcall("SADD", parentKey .. ":dependencies", jobKey)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -31,6 +31,7 @@ local rcall = redis.call;
31
31
  --- @include "includes/batches"
32
32
  --- @include "includes/getOrSetMaxEvents"
33
33
  --- @include "includes/isQueuePausedOrMaxed"
34
+ --- @include "includes/moveChildBackToParentDependencies"
34
35
 
35
36
  local metaKey = KEYS[6]
36
37
  local isPausedOrMaxed = isQueuePausedOrMaxed(metaKey, KEYS[7])
@@ -42,11 +43,13 @@ if (#jobs > 0) then
42
43
  for i, key in ipairs(jobs) do
43
44
  local jobKey = KEYS[1] .. key
44
45
  rcall("HDEL", jobKey, "finishedOn", "processedOn", "failedReason")
46
+ moveChildBackToParentDependencies(jobKey, ARGV[3])
45
47
  end
46
48
  elseif ARGV[3] == "completed" then
47
49
  for i, key in ipairs(jobs) do
48
50
  local jobKey = KEYS[1] .. key
49
51
  rcall("HDEL", jobKey, "finishedOn", "processedOn", "returnvalue")
52
+ moveChildBackToParentDependencies(jobKey, ARGV[3])
50
53
  end
51
54
  end
52
55
 
@@ -28,6 +28,7 @@ local rcall = redis.call;
28
28
  --- @include "includes/addJobInTargetList"
29
29
  --- @include "includes/getOrSetMaxEvents"
30
30
  --- @include "includes/isQueuePausedOrMaxed"
31
+ --- @include "includes/moveChildBackToParentDependencies"
31
32
 
32
33
  local jobKey = KEYS[1]
33
34
  if rcall("EXISTS", jobKey) == 1 then
@@ -48,20 +49,7 @@ if rcall("EXISTS", jobKey) == 1 then
48
49
  local isPausedOrMaxed = isQueuePausedOrMaxed(KEYS[5], KEYS[6])
49
50
  addJobInTargetList(KEYS[4], KEYS[7], ARGV[2], isPausedOrMaxed, jobId)
50
51
 
51
- local parentKey = rcall("HGET", jobKey, "parentKey")
52
-
53
- if parentKey and rcall("EXISTS", parentKey) == 1 then
54
- if ARGV[4] == "failed" then
55
- if rcall("ZREM", parentKey .. ":unsuccessful", jobKey) == 1 or
56
- rcall("HDEL", parentKey .. ":failed", jobKey) == 1 then
57
- rcall("SADD", parentKey .. ":dependencies", jobKey)
58
- end
59
- else
60
- if rcall("HDEL", parentKey .. ":processed", jobKey) == 1 then
61
- rcall("SADD", parentKey .. ":dependencies", jobKey)
62
- end
63
- end
64
- end
52
+ moveChildBackToParentDependencies(jobKey, ARGV[4])
65
53
 
66
54
  local maxEvents = getOrSetMaxEvents(KEYS[5])
67
55
  -- Emit waiting event
@@ -72,6 +72,25 @@ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
72
72
  end
73
73
  return false
74
74
  end
75
+ --[[
76
+ Function to move a retried child back to its parent's dependencies.
77
+ This does not move a parent that has already left waiting-children back to that state.
78
+ ]]
79
+ local function moveChildBackToParentDependencies(jobKey, prevState)
80
+ local parentKey = rcall("HGET", jobKey, "parentKey")
81
+ if parentKey and rcall("EXISTS", parentKey) == 1 then
82
+ if prevState == "failed" then
83
+ if rcall("ZREM", parentKey .. ":unsuccessful", jobKey) == 1 or
84
+ rcall("HDEL", parentKey .. ":failed", jobKey) == 1 then
85
+ rcall("SADD", parentKey .. ":dependencies", jobKey)
86
+ end
87
+ else
88
+ if rcall("HDEL", parentKey .. ":processed", jobKey) == 1 then
89
+ rcall("SADD", parentKey .. ":dependencies", jobKey)
90
+ end
91
+ end
92
+ end
93
+ end
75
94
  local metaKey = KEYS[6]
76
95
  local isPausedOrMaxed = isQueuePausedOrMaxed(metaKey, KEYS[7])
77
96
  local jobs = rcall('ZRANGEBYSCORE', KEYS[3], 0, timestamp, 'LIMIT', 0, maxCount)
@@ -80,11 +99,13 @@ if (#jobs > 0) then
80
99
  for i, key in ipairs(jobs) do
81
100
  local jobKey = KEYS[1] .. key
82
101
  rcall("HDEL", jobKey, "finishedOn", "processedOn", "failedReason")
102
+ moveChildBackToParentDependencies(jobKey, ARGV[3])
83
103
  end
84
104
  elseif ARGV[3] == "completed" then
85
105
  for i, key in ipairs(jobs) do
86
106
  local jobKey = KEYS[1] .. key
87
107
  rcall("HDEL", jobKey, "finishedOn", "processedOn", "returnvalue")
108
+ moveChildBackToParentDependencies(jobKey, ARGV[3])
88
109
  end
89
110
  end
90
111
  local maxEvents = getOrSetMaxEvents(metaKey)
@@ -64,6 +64,25 @@ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
64
64
  end
65
65
  return false
66
66
  end
67
+ --[[
68
+ Function to move a retried child back to its parent's dependencies.
69
+ This does not move a parent that has already left waiting-children back to that state.
70
+ ]]
71
+ local function moveChildBackToParentDependencies(jobKey, prevState)
72
+ local parentKey = rcall("HGET", jobKey, "parentKey")
73
+ if parentKey and rcall("EXISTS", parentKey) == 1 then
74
+ if prevState == "failed" then
75
+ if rcall("ZREM", parentKey .. ":unsuccessful", jobKey) == 1 or
76
+ rcall("HDEL", parentKey .. ":failed", jobKey) == 1 then
77
+ rcall("SADD", parentKey .. ":dependencies", jobKey)
78
+ end
79
+ else
80
+ if rcall("HDEL", parentKey .. ":processed", jobKey) == 1 then
81
+ rcall("SADD", parentKey .. ":dependencies", jobKey)
82
+ end
83
+ end
84
+ end
85
+ end
67
86
  local jobKey = KEYS[1]
68
87
  if rcall("EXISTS", jobKey) == 1 then
69
88
  local jobId = ARGV[1]
@@ -78,19 +97,7 @@ if rcall("EXISTS", jobKey) == 1 then
78
97
  rcall("HDEL", jobKey, "finishedOn", "processedOn", ARGV[3], unpack(attributesToRemove))
79
98
  local isPausedOrMaxed = isQueuePausedOrMaxed(KEYS[5], KEYS[6])
80
99
  addJobInTargetList(KEYS[4], KEYS[7], ARGV[2], isPausedOrMaxed, jobId)
81
- local parentKey = rcall("HGET", jobKey, "parentKey")
82
- if parentKey and rcall("EXISTS", parentKey) == 1 then
83
- if ARGV[4] == "failed" then
84
- if rcall("ZREM", parentKey .. ":unsuccessful", jobKey) == 1 or
85
- rcall("HDEL", parentKey .. ":failed", jobKey) == 1 then
86
- rcall("SADD", parentKey .. ":dependencies", jobKey)
87
- end
88
- else
89
- if rcall("HDEL", parentKey .. ":processed", jobKey) == 1 then
90
- rcall("SADD", parentKey .. ":dependencies", jobKey)
91
- end
92
- end
93
- end
100
+ moveChildBackToParentDependencies(jobKey, ARGV[4])
94
101
  local maxEvents = getOrSetMaxEvents(KEYS[5])
95
102
  -- Emit waiting event
96
103
  rcall("XADD", KEYS[2], "MAXLEN", "~", maxEvents, "*", "event", "waiting",