bullmq 1.64.1 → 1.64.2

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,30 @@
1
+ --[[
2
+ Check if this job has a parent. If so we will just remove it from
3
+ the parent child list, but if it is the last child we should move the parent to "wait/paused"
4
+ which requires code from "moveToFinished"
5
+ ]]
6
+
7
+ --- @include "destructureJobKey"
8
+
9
+ local function removeParentDependencyKey(jobKey)
10
+ local parentKey = rcall("HGET", jobKey, "parentKey")
11
+ if( (type(parentKey) == "string") and parentKey ~= "" and (rcall("EXISTS", parentKey) == 1)) then
12
+ local parentDependenciesKey = parentKey .. ":dependencies"
13
+ local result = rcall("SREM", parentDependenciesKey, jobKey)
14
+ if result > 0 and rcall("SCARD", parentDependenciesKey) == 0 then
15
+ local parentId = getJobIdFromKey(parentKey)
16
+ local parentPrefix = getJobKeyPrefix(parentKey, parentId)
17
+
18
+ rcall("ZREM", parentPrefix .. "waiting-children", parentId)
19
+
20
+ if rcall("HEXISTS", parentPrefix .. "meta", "paused") ~= 1 then
21
+ rcall("RPUSH", parentPrefix .. "wait", parentId)
22
+ else
23
+ rcall("RPUSH", parentPrefix .. "paused", parentId)
24
+ end
25
+
26
+ local parentEventStream = parentPrefix .. "events"
27
+ rcall("XADD", parentEventStream, "*", "event", "active", "jobId", parentId, "prev", "waiting-children")
28
+ end
29
+ end
30
+ end
@@ -44,6 +44,7 @@ local rcall = redis.call
44
44
  -- Includes
45
45
  --- @include "includes/updateParentDepsIfNeeded"
46
46
  --- @include "includes/destructureJobKey"
47
+ --- @include "includes/removeParentDependencyKey"
47
48
 
48
49
  local jobIdKey = KEYS[3]
49
50
  if rcall("EXISTS",jobIdKey) == 1 then -- // Make sure job exists
@@ -114,6 +115,7 @@ if rcall("EXISTS",jobIdKey) == 1 then -- // Make sure job exists
114
115
  local jobIds = rcall("ZREVRANGE", KEYS[2], start, -1)
115
116
  for i, jobId in ipairs(jobIds) do
116
117
  local jobKey = ARGV[9] .. jobId
118
+ removeParentDependencyKey(jobKey)
117
119
  local jobLogKey = jobKey .. ':logs'
118
120
  local jobProcessedKey = jobKey .. ':processed'
119
121
  rcall("DEL", jobKey, jobLogKey, jobProcessedKey)
@@ -32,9 +32,12 @@ local function getSetItems(keyName, max)
32
32
  return rcall('SMEMBERS', keyName, 0, max)
33
33
  end
34
34
 
35
+ --- @include "includes/removeParentDependencyKey"
36
+
35
37
  local function removeJobs(keys)
36
38
  for i, key in ipairs(keys) do
37
- local jobKey = baseKey .. key
39
+ local jobKey = baseKey .. key
40
+ removeParentDependencyKey(jobKey)
38
41
  rcall("DEL", jobKey)
39
42
  rcall("DEL", jobKey .. ':logs')
40
43
  rcall("DEL", jobKey .. ':dependencies')
@@ -84,12 +87,6 @@ if(maxCount <= 0) then
84
87
  return 1
85
88
  end
86
89
 
87
- local waitKey = baseKey .. 'paused'
88
- removeListJobs(waitKey, maxCount)
89
- if(maxCount <= 0) then
90
- return 1
91
- end
92
-
93
90
  local delayedKey = baseKey .. 'delayed'
94
91
  removeZSetJobs(delayedKey, maxCount)
95
92
  if(maxCount <= 0) then
@@ -108,6 +105,12 @@ if(maxCount <= 0) then
108
105
  return 1
109
106
  end
110
107
 
108
+ local waitKey = baseKey .. 'paused'
109
+ removeListJobs(waitKey, maxCount)
110
+ if(maxCount <= 0) then
111
+ return 1
112
+ end
113
+
111
114
  local waitingChildrenKey = baseKey .. 'waiting-children'
112
115
  removeZSetJobs(waitingChildrenKey, maxCount)
113
116
  if(maxCount <= 0) then
@@ -14,6 +14,7 @@ local rcall = redis.call
14
14
 
15
15
  -- Includes
16
16
  --- @include "includes/destructureJobKey"
17
+ --- @include "includes/removeParentDependencyKey"
17
18
 
18
19
  -- recursively check if there are no locks on the
19
20
  -- jobs to be removed.
@@ -44,29 +45,7 @@ end
44
45
  local function removeJob( prefix, jobId)
45
46
  local jobKey = prefix .. jobId;
46
47
 
47
- -- Check if this job has a parent. If so we will just remove it from
48
- -- the parent child list, but if it is the last child we should move the parent to "wait/paused"
49
- -- which requires code from "moveToFinished"
50
- local parentKey = rcall("HGET", jobKey, "parentKey")
51
- if( (type(parentKey) == "string") and parentKey ~= "" and (rcall("EXISTS", parentKey) == 1)) then
52
- local parentDependenciesKey = parentKey .. ":dependencies"
53
- local result = rcall("SREM", parentDependenciesKey, jobKey)
54
- if rcall("SCARD", parentDependenciesKey) == 0 then
55
- local parentId = getJobIdFromKey(parentKey)
56
- local parentPrefix = getJobKeyPrefix(parentKey, parentId)
57
-
58
- rcall("ZREM", parentPrefix .. "waiting-children", parentId)
59
-
60
- if rcall("HEXISTS", parentPrefix .. "meta", "paused") ~= 1 then
61
- rcall("RPUSH", parentPrefix .. "wait", parentId)
62
- else
63
- rcall("RPUSH", parentPrefix .. "parentPrefixpaused", parentId)
64
- end
65
-
66
- local parentEventStream = parentPrefix .. "events"
67
- rcall("XADD", parentEventStream, "*", "event", "active", "jobId", parentId, "prev", "waiting-children")
68
- end
69
- end
48
+ removeParentDependencyKey(jobKey)
70
49
 
71
50
  rcall("LREM", prefix .. "active", 0, jobId)
72
51
  rcall("LREM", prefix .. "wait", 0, jobId)
@@ -0,0 +1,30 @@
1
+ --[[
2
+ Check if this job has a parent. If so we will just remove it from
3
+ the parent child list, but if it is the last child we should move the parent to "wait/paused"
4
+ which requires code from "moveToFinished"
5
+ ]]
6
+
7
+ --- @include "destructureJobKey"
8
+
9
+ local function removeParentDependencyKey(jobKey)
10
+ local parentKey = rcall("HGET", jobKey, "parentKey")
11
+ if( (type(parentKey) == "string") and parentKey ~= "" and (rcall("EXISTS", parentKey) == 1)) then
12
+ local parentDependenciesKey = parentKey .. ":dependencies"
13
+ local result = rcall("SREM", parentDependenciesKey, jobKey)
14
+ if result > 0 and rcall("SCARD", parentDependenciesKey) == 0 then
15
+ local parentId = getJobIdFromKey(parentKey)
16
+ local parentPrefix = getJobKeyPrefix(parentKey, parentId)
17
+
18
+ rcall("ZREM", parentPrefix .. "waiting-children", parentId)
19
+
20
+ if rcall("HEXISTS", parentPrefix .. "meta", "paused") ~= 1 then
21
+ rcall("RPUSH", parentPrefix .. "wait", parentId)
22
+ else
23
+ rcall("RPUSH", parentPrefix .. "paused", parentId)
24
+ end
25
+
26
+ local parentEventStream = parentPrefix .. "events"
27
+ rcall("XADD", parentEventStream, "*", "event", "active", "jobId", parentId, "prev", "waiting-children")
28
+ end
29
+ end
30
+ end
@@ -44,6 +44,7 @@ local rcall = redis.call
44
44
  -- Includes
45
45
  --- @include "includes/updateParentDepsIfNeeded"
46
46
  --- @include "includes/destructureJobKey"
47
+ --- @include "includes/removeParentDependencyKey"
47
48
 
48
49
  local jobIdKey = KEYS[3]
49
50
  if rcall("EXISTS",jobIdKey) == 1 then -- // Make sure job exists
@@ -114,6 +115,7 @@ if rcall("EXISTS",jobIdKey) == 1 then -- // Make sure job exists
114
115
  local jobIds = rcall("ZREVRANGE", KEYS[2], start, -1)
115
116
  for i, jobId in ipairs(jobIds) do
116
117
  local jobKey = ARGV[9] .. jobId
118
+ removeParentDependencyKey(jobKey)
117
119
  local jobLogKey = jobKey .. ':logs'
118
120
  local jobProcessedKey = jobKey .. ':processed'
119
121
  rcall("DEL", jobKey, jobLogKey, jobProcessedKey)
@@ -32,9 +32,12 @@ local function getSetItems(keyName, max)
32
32
  return rcall('SMEMBERS', keyName, 0, max)
33
33
  end
34
34
 
35
+ --- @include "includes/removeParentDependencyKey"
36
+
35
37
  local function removeJobs(keys)
36
38
  for i, key in ipairs(keys) do
37
- local jobKey = baseKey .. key
39
+ local jobKey = baseKey .. key
40
+ removeParentDependencyKey(jobKey)
38
41
  rcall("DEL", jobKey)
39
42
  rcall("DEL", jobKey .. ':logs')
40
43
  rcall("DEL", jobKey .. ':dependencies')
@@ -84,12 +87,6 @@ if(maxCount <= 0) then
84
87
  return 1
85
88
  end
86
89
 
87
- local waitKey = baseKey .. 'paused'
88
- removeListJobs(waitKey, maxCount)
89
- if(maxCount <= 0) then
90
- return 1
91
- end
92
-
93
90
  local delayedKey = baseKey .. 'delayed'
94
91
  removeZSetJobs(delayedKey, maxCount)
95
92
  if(maxCount <= 0) then
@@ -108,6 +105,12 @@ if(maxCount <= 0) then
108
105
  return 1
109
106
  end
110
107
 
108
+ local waitKey = baseKey .. 'paused'
109
+ removeListJobs(waitKey, maxCount)
110
+ if(maxCount <= 0) then
111
+ return 1
112
+ end
113
+
111
114
  local waitingChildrenKey = baseKey .. 'waiting-children'
112
115
  removeZSetJobs(waitingChildrenKey, maxCount)
113
116
  if(maxCount <= 0) then
@@ -14,6 +14,7 @@ local rcall = redis.call
14
14
 
15
15
  -- Includes
16
16
  --- @include "includes/destructureJobKey"
17
+ --- @include "includes/removeParentDependencyKey"
17
18
 
18
19
  -- recursively check if there are no locks on the
19
20
  -- jobs to be removed.
@@ -44,29 +45,7 @@ end
44
45
  local function removeJob( prefix, jobId)
45
46
  local jobKey = prefix .. jobId;
46
47
 
47
- -- Check if this job has a parent. If so we will just remove it from
48
- -- the parent child list, but if it is the last child we should move the parent to "wait/paused"
49
- -- which requires code from "moveToFinished"
50
- local parentKey = rcall("HGET", jobKey, "parentKey")
51
- if( (type(parentKey) == "string") and parentKey ~= "" and (rcall("EXISTS", parentKey) == 1)) then
52
- local parentDependenciesKey = parentKey .. ":dependencies"
53
- local result = rcall("SREM", parentDependenciesKey, jobKey)
54
- if rcall("SCARD", parentDependenciesKey) == 0 then
55
- local parentId = getJobIdFromKey(parentKey)
56
- local parentPrefix = getJobKeyPrefix(parentKey, parentId)
57
-
58
- rcall("ZREM", parentPrefix .. "waiting-children", parentId)
59
-
60
- if rcall("HEXISTS", parentPrefix .. "meta", "paused") ~= 1 then
61
- rcall("RPUSH", parentPrefix .. "wait", parentId)
62
- else
63
- rcall("RPUSH", parentPrefix .. "parentPrefixpaused", parentId)
64
- end
65
-
66
- local parentEventStream = parentPrefix .. "events"
67
- rcall("XADD", parentEventStream, "*", "event", "active", "jobId", parentId, "prev", "waiting-children")
68
- end
69
- end
48
+ removeParentDependencyKey(jobKey)
70
49
 
71
50
  rcall("LREM", prefix .. "active", 0, jobId)
72
51
  rcall("LREM", prefix .. "wait", 0, jobId)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bullmq",
3
- "version": "1.64.1",
3
+ "version": "1.64.2",
4
4
  "description": "Queue for messages and jobs based on Redis",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",