@tachybase/plugin-adapter-bullmq 1.3.24 → 1.4.0

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.
Files changed (42) hide show
  1. package/dist/externalVersion.js +2 -2
  2. package/dist/node_modules/@bull-board/api/package.json +1 -1
  3. package/dist/node_modules/@bull-board/koa/dist/index.js +1 -1
  4. package/dist/node_modules/@bull-board/koa/package.json +1 -1
  5. package/dist/node_modules/bullmq/dist/cjs/classes/queue.js +4 -2
  6. package/dist/node_modules/bullmq/dist/cjs/classes/scripts.js +3 -3
  7. package/dist/node_modules/bullmq/dist/cjs/classes/worker.js +8 -9
  8. package/dist/node_modules/bullmq/dist/cjs/commands/includes/moveJobToWait.lua +15 -0
  9. package/dist/node_modules/bullmq/dist/cjs/commands/moveJobFromActiveToWait-9.lua +5 -1
  10. package/dist/node_modules/bullmq/dist/cjs/commands/moveStalledJobsToWait-8.lua +3 -11
  11. package/dist/node_modules/bullmq/dist/cjs/commands/{moveToWaitingChildren-8.lua → moveToWaitingChildren-7.lua} +29 -40
  12. package/dist/node_modules/bullmq/dist/cjs/enums/error-code.js +1 -1
  13. package/dist/node_modules/bullmq/dist/cjs/index.js +1 -1
  14. package/dist/node_modules/bullmq/dist/cjs/scripts/index.js +1 -1
  15. package/dist/node_modules/bullmq/dist/cjs/scripts/moveJobFromActiveToWait-9.js +5 -1
  16. package/dist/node_modules/bullmq/dist/cjs/scripts/moveStalledJobsToWait-8.js +12 -8
  17. package/dist/node_modules/bullmq/dist/cjs/scripts/moveToWaitingChildren-7.js +107 -0
  18. package/dist/node_modules/bullmq/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  19. package/dist/node_modules/bullmq/dist/cjs/version.js +1 -1
  20. package/dist/node_modules/bullmq/dist/esm/classes/queue.d.ts +1 -1
  21. package/dist/node_modules/bullmq/dist/esm/classes/queue.js +4 -2
  22. package/dist/node_modules/bullmq/dist/esm/classes/scripts.js +3 -3
  23. package/dist/node_modules/bullmq/dist/esm/classes/worker.js +8 -9
  24. package/dist/node_modules/bullmq/dist/esm/commands/includes/moveJobToWait.lua +15 -0
  25. package/dist/node_modules/bullmq/dist/esm/commands/moveJobFromActiveToWait-9.lua +5 -1
  26. package/dist/node_modules/bullmq/dist/esm/commands/moveStalledJobsToWait-8.lua +3 -11
  27. package/dist/node_modules/bullmq/dist/esm/commands/{moveToWaitingChildren-8.lua → moveToWaitingChildren-7.lua} +29 -40
  28. package/dist/node_modules/bullmq/dist/esm/enums/error-code.d.ts +1 -1
  29. package/dist/node_modules/bullmq/dist/esm/enums/error-code.js +1 -1
  30. package/dist/node_modules/bullmq/dist/esm/scripts/index.d.ts +1 -1
  31. package/dist/node_modules/bullmq/dist/esm/scripts/index.js +1 -1
  32. package/dist/node_modules/bullmq/dist/esm/scripts/moveJobFromActiveToWait-9.js +5 -1
  33. package/dist/node_modules/bullmq/dist/esm/scripts/moveStalledJobsToWait-8.js +12 -8
  34. package/dist/node_modules/bullmq/dist/esm/scripts/moveToWaitingChildren-7.js +104 -0
  35. package/dist/node_modules/bullmq/dist/esm/tsconfig.tsbuildinfo +1 -1
  36. package/dist/node_modules/bullmq/dist/esm/version.d.ts +1 -1
  37. package/dist/node_modules/bullmq/dist/esm/version.js +1 -1
  38. package/dist/node_modules/bullmq/package.json +1 -1
  39. package/package.json +6 -6
  40. package/dist/node_modules/bullmq/dist/cjs/scripts/moveToWaitingChildren-8.js +0 -529
  41. package/dist/node_modules/bullmq/dist/esm/scripts/moveToWaitingChildren-8.js +0 -526
  42. /package/dist/node_modules/bullmq/dist/esm/scripts/{moveToWaitingChildren-8.d.ts → moveToWaitingChildren-7.d.ts} +0 -0
@@ -25,6 +25,7 @@ local rcall = redis.call
25
25
  --- @include "includes/addJobInTargetList"
26
26
  --- @include "includes/batches"
27
27
  --- @include "includes/getTargetQueueList"
28
+ --- @include "includes/moveJobToWait"
28
29
  --- @include "includes/trimEvents"
29
30
 
30
31
  local stalledKey = KEYS[1]
@@ -73,20 +74,11 @@ if (#stalling > 0) then
73
74
  -- If this job has been stalled too many times, such as if it crashes the worker, then fail it.
74
75
  local stalledCount = rcall("HINCRBY", jobKey, "stc", 1)
75
76
  if stalledCount > maxStalledJobCount then
76
- local jobAttributes = rcall("HMGET", jobKey, "opts", "parent")
77
- local rawOpts = jobAttributes[1]
78
- local rawParentData = jobAttributes[2]
79
- local opts = cjson.decode(rawOpts)
80
-
81
77
  local failedReason = "job stalled more than allowable limit"
82
78
  rcall("HSET", jobKey, "defa", failedReason)
83
79
  end
84
- local target, isPausedOrMaxed = getTargetQueueList(metaKey, activeKey, waitKey, pausedKey)
85
-
86
- -- Move the job back to the wait queue, to immediately be picked up by a waiting worker.
87
- addJobInTargetList(target, markerKey, "RPUSH", isPausedOrMaxed, jobId)
88
-
89
- rcall("XADD", eventStreamKey, "*", "event", "waiting", "jobId", jobId, 'prev', 'active')
80
+ moveJobToWait(metaKey, activeKey, waitKey, pausedKey, markerKey, eventStreamKey, jobId,
81
+ "RPUSH")
90
82
 
91
83
  -- Emit the stalled event
92
84
  rcall("XADD", eventStreamKey, "*", "event", "stalled", "jobId", jobId)
@@ -8,8 +8,7 @@
8
8
  KEYS[4] job dependencies key
9
9
  KEYS[5] job unsuccessful key
10
10
  KEYS[6] stalled key
11
- KEYS[7] failed key
12
- KEYS[8] events key
11
+ KEYS[7] events key
13
12
 
14
13
  ARGV[1] token
15
14
  ARGV[2] child key
@@ -23,6 +22,7 @@
23
22
  -1 - Missing job.
24
23
  -2 - Missing lock
25
24
  -3 - Job not in active set
25
+ -9 - Job has failed children
26
26
  ]]
27
27
  local rcall = redis.call
28
28
  local activeKey = KEYS[1]
@@ -31,71 +31,60 @@ local jobKey = KEYS[3]
31
31
  local jobDependenciesKey = KEYS[4]
32
32
  local jobUnsuccessfulKey = KEYS[5]
33
33
  local stalledKey = KEYS[6]
34
- local failedKey = KEYS[7]
34
+ local eventStreamKey = KEYS[7]
35
+ local token = ARGV[1]
35
36
  local timestamp = ARGV[3]
36
37
  local jobId = ARGV[4]
37
38
 
38
39
  --- Includes
39
- --- @include "includes/moveChildFromDependenciesIfNeeded"
40
- --- @include "includes/removeDeduplicationKeyIfNeededOnFinalization"
41
- --- @include "includes/removeJobsOnFail"
42
40
  --- @include "includes/removeLock"
43
41
 
44
- local function moveToWaitingChildren(activeKey, waitingChildrenKey, jobId,
45
- timestamp)
46
- local score = tonumber(timestamp)
42
+ local function removeJobFromActive(activeKey, stalledKey, jobKey, jobId,
43
+ token)
44
+ local errorCode = removeLock(jobKey, stalledKey, token, jobId)
45
+ if errorCode < 0 then
46
+ return errorCode
47
+ end
47
48
 
48
49
  local numRemovedElements = rcall("LREM", activeKey, -1, jobId)
49
50
 
50
- if(numRemovedElements < 1) then
51
+ if numRemovedElements < 1 then
51
52
  return -3
52
53
  end
53
54
 
54
- rcall("ZADD", waitingChildrenKey, score, jobId)
55
-
56
55
  return 0
57
56
  end
58
57
 
59
- if rcall("EXISTS", jobKey) == 1 then
60
- if rcall("ZCARD", jobUnsuccessfulKey) ~= 0 then
61
- -- TODO: refactor this logic in an include later
62
- local jobAttributes = rcall("HMGET", jobKey, "parent", "deid", "opts")
63
-
64
- removeDeduplicationKeyIfNeededOnFinalization(ARGV[5], jobAttributes[2], jobId)
65
-
66
- local failedReason = "children are failed"
67
- rcall("ZADD", failedKey, timestamp, jobId)
68
- rcall("HSET", jobKey, "finishedOn", timestamp)
69
- rcall("XADD", KEYS[8], "*", "event", "failed", "jobId", jobId, "failedReason",
70
- failedReason, "prev", "active")
58
+ local function moveToWaitingChildren(activeKey, waitingChildrenKey, stalledKey, eventStreamKey,
59
+ jobKey, jobId, timestamp, token)
60
+ local errorCode = removeJobFromActive(activeKey, stalledKey, jobKey, jobId, token)
61
+ if errorCode < 0 then
62
+ return errorCode
63
+ end
71
64
 
72
- local rawParentData = jobAttributes[1]
73
- local rawOpts = jobAttributes[3]
74
- local opts = cjson.decode(rawOpts)
65
+ local score = tonumber(timestamp)
75
66
 
76
- moveChildFromDependenciesIfNeeded(rawParentData, jobKey, failedReason, timestamp)
67
+ rcall("ZADD", waitingChildrenKey, score, jobId)
68
+ rcall("XADD", eventStreamKey, "*", "event", "waiting-children", "jobId", jobId, 'prev', 'active')
77
69
 
78
- removeJobsOnFail(ARGV[5], failedKey, jobId, opts, timestamp)
70
+ return 0
71
+ end
79
72
 
80
- return 0
73
+ if rcall("EXISTS", jobKey) == 1 then
74
+ if rcall("ZCARD", jobUnsuccessfulKey) ~= 0 then
75
+ return -9
81
76
  else
82
77
  if ARGV[2] ~= "" then
83
78
  if rcall("SISMEMBER", jobDependenciesKey, ARGV[2]) ~= 0 then
84
- local errorCode = removeLock(jobKey, stalledKey, ARGV[1], jobId)
85
- if errorCode < 0 then
86
- return errorCode
87
- end
88
- return moveToWaitingChildren(activeKey, waitingChildrenKey, jobId, timestamp)
79
+ return moveToWaitingChildren(activeKey, waitingChildrenKey, stalledKey, eventStreamKey,
80
+ jobKey, jobId, timestamp, token)
89
81
  end
90
82
 
91
83
  return 1
92
84
  else
93
85
  if rcall("SCARD", jobDependenciesKey) ~= 0 then
94
- local errorCode = removeLock(jobKey, stalledKey, ARGV[1], jobId)
95
- if errorCode < 0 then
96
- return errorCode
97
- end
98
- return moveToWaitingChildren(activeKey, waitingChildrenKey, jobId, timestamp)
86
+ return moveToWaitingChildren(activeKey, waitingChildrenKey, stalledKey, eventStreamKey,
87
+ jobKey, jobId, timestamp, token)
99
88
  end
100
89
 
101
90
  return 1
@@ -11,6 +11,6 @@ var ErrorCode;
11
11
  ErrorCode[ErrorCode["JobLockMismatch"] = -6] = "JobLockMismatch";
12
12
  ErrorCode[ErrorCode["ParentJobCannotBeReplaced"] = -7] = "ParentJobCannotBeReplaced";
13
13
  ErrorCode[ErrorCode["JobBelongsToJobScheduler"] = -8] = "JobBelongsToJobScheduler";
14
- ErrorCode[ErrorCode["JobFailedChildren"] = -9] = "JobFailedChildren";
14
+ ErrorCode[ErrorCode["JobHasFailedChildren"] = -9] = "JobHasFailedChildren";
15
15
  })(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));
16
16
  //# sourceMappingURL=error-code.js.map