@tachybase/plugin-print-template 1.3.23 → 1.3.25

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 (41) hide show
  1. package/dist/externalVersion.js +2 -2
  2. package/dist/node_modules/bullmq/dist/cjs/classes/queue.js +4 -2
  3. package/dist/node_modules/bullmq/dist/cjs/classes/scripts.js +3 -3
  4. package/dist/node_modules/bullmq/dist/cjs/classes/worker.js +8 -9
  5. package/dist/node_modules/bullmq/dist/cjs/commands/includes/moveJobToWait.lua +15 -0
  6. package/dist/node_modules/bullmq/dist/cjs/commands/moveJobFromActiveToWait-9.lua +5 -1
  7. package/dist/node_modules/bullmq/dist/cjs/commands/moveStalledJobsToWait-8.lua +3 -11
  8. package/dist/node_modules/bullmq/dist/cjs/commands/{moveToWaitingChildren-8.lua → moveToWaitingChildren-7.lua} +29 -40
  9. package/dist/node_modules/bullmq/dist/cjs/enums/error-code.js +1 -1
  10. package/dist/node_modules/bullmq/dist/cjs/index.js +1 -1
  11. package/dist/node_modules/bullmq/dist/cjs/scripts/index.js +1 -1
  12. package/dist/node_modules/bullmq/dist/cjs/scripts/moveJobFromActiveToWait-9.js +5 -1
  13. package/dist/node_modules/bullmq/dist/cjs/scripts/moveStalledJobsToWait-8.js +12 -8
  14. package/dist/node_modules/bullmq/dist/cjs/scripts/moveToWaitingChildren-7.js +107 -0
  15. package/dist/node_modules/bullmq/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  16. package/dist/node_modules/bullmq/dist/cjs/version.js +1 -1
  17. package/dist/node_modules/bullmq/dist/esm/classes/queue.d.ts +1 -1
  18. package/dist/node_modules/bullmq/dist/esm/classes/queue.js +4 -2
  19. package/dist/node_modules/bullmq/dist/esm/classes/scripts.js +3 -3
  20. package/dist/node_modules/bullmq/dist/esm/classes/worker.js +8 -9
  21. package/dist/node_modules/bullmq/dist/esm/commands/includes/moveJobToWait.lua +15 -0
  22. package/dist/node_modules/bullmq/dist/esm/commands/moveJobFromActiveToWait-9.lua +5 -1
  23. package/dist/node_modules/bullmq/dist/esm/commands/moveStalledJobsToWait-8.lua +3 -11
  24. package/dist/node_modules/bullmq/dist/esm/commands/{moveToWaitingChildren-8.lua → moveToWaitingChildren-7.lua} +29 -40
  25. package/dist/node_modules/bullmq/dist/esm/enums/error-code.d.ts +1 -1
  26. package/dist/node_modules/bullmq/dist/esm/enums/error-code.js +1 -1
  27. package/dist/node_modules/bullmq/dist/esm/scripts/index.d.ts +1 -1
  28. package/dist/node_modules/bullmq/dist/esm/scripts/index.js +1 -1
  29. package/dist/node_modules/bullmq/dist/esm/scripts/moveJobFromActiveToWait-9.js +5 -1
  30. package/dist/node_modules/bullmq/dist/esm/scripts/moveStalledJobsToWait-8.js +12 -8
  31. package/dist/node_modules/bullmq/dist/esm/scripts/moveToWaitingChildren-7.js +104 -0
  32. package/dist/node_modules/bullmq/dist/esm/tsconfig.tsbuildinfo +1 -1
  33. package/dist/node_modules/bullmq/dist/esm/version.d.ts +1 -1
  34. package/dist/node_modules/bullmq/dist/esm/version.js +1 -1
  35. package/dist/node_modules/bullmq/package.json +1 -1
  36. package/dist/node_modules/docxtemplater/package.json +1 -1
  37. package/dist/node_modules/pizzip/package.json +1 -1
  38. package/package.json +6 -6
  39. package/dist/node_modules/bullmq/dist/cjs/scripts/moveToWaitingChildren-8.js +0 -529
  40. package/dist/node_modules/bullmq/dist/esm/scripts/moveToWaitingChildren-8.js +0 -526
  41. /package/dist/node_modules/bullmq/dist/esm/scripts/{moveToWaitingChildren-8.d.ts → moveToWaitingChildren-7.d.ts} +0 -0
@@ -1,5 +1,5 @@
1
1
  module.exports = {
2
- "@tachybase/client": "1.3.23",
3
- "@tego/server": "1.3.43",
2
+ "@tachybase/client": "1.3.25",
3
+ "@tego/server": "1.3.52",
4
4
  "koa-bodyparser": "4.4.1"
5
5
  };
@@ -537,9 +537,11 @@ class Queue extends queue_getters_1.QueueGetters {
537
537
  const timestamp = Date.now() - grace;
538
538
  let deletedCount = 0;
539
539
  const deletedJobsIds = [];
540
+ // Normalize 'waiting' to 'wait' for consistency with internal Redis keys
541
+ const normalizedType = type === 'waiting' ? 'wait' : type;
540
542
  while (deletedCount < maxCount) {
541
- const jobsIds = await this.scripts.cleanJobsInSet(type, timestamp, maxCountPerCall);
542
- this.emit('cleaned', jobsIds, type);
543
+ const jobsIds = await this.scripts.cleanJobsInSet(normalizedType, timestamp, maxCountPerCall);
544
+ this.emit('cleaned', jobsIds, normalizedType);
543
545
  deletedCount += jobsIds.length;
544
546
  deletedJobsIds.push(...jobsIds);
545
547
  if (jobsIds.length < maxCountPerCall) {
@@ -14,6 +14,7 @@ const pack = packer.pack;
14
14
  const enums_1 = require("../enums");
15
15
  const utils_1 = require("../utils");
16
16
  const version_1 = require("../version");
17
+ const errors_1 = require("./errors");
17
18
  class Scripts {
18
19
  constructor(queue) {
19
20
  this.queue = queue;
@@ -694,7 +695,6 @@ class Scripts {
694
695
  `${jobId}:dependencies`,
695
696
  `${jobId}:unsuccessful`,
696
697
  'stalled',
697
- 'failed',
698
698
  'events',
699
699
  ].map(name => {
700
700
  return this.queue.toKey(name);
@@ -1115,8 +1115,8 @@ class Scripts {
1115
1115
  return new Error(`The parent job ${parentKey} cannot be replaced. ${command}`);
1116
1116
  case enums_1.ErrorCode.JobBelongsToJobScheduler:
1117
1117
  return new Error(`Job ${jobId} belongs to a job scheduler and cannot be removed directly. ${command}`);
1118
- case enums_1.ErrorCode.JobFailedChildren:
1119
- return new Error(`Job ${jobId} has failed children. ${command}`);
1118
+ case enums_1.ErrorCode.JobHasFailedChildren:
1119
+ return new errors_1.UnrecoverableError(`Cannot complete job ${jobId} because it has at least one failed child. ${command}`);
1120
1120
  default:
1121
1121
  return new Error(`Unknown code ${code} error for ${jobId}. ${command}`);
1122
1122
  }
@@ -225,8 +225,7 @@ class Worker extends queue_base_1.QueueBase {
225
225
  const jobsInProgress = new Set();
226
226
  this.startLockExtenderTimer(jobsInProgress);
227
227
  let tokenPostfix = 0;
228
- while (!this.closing && !this.paused) {
229
- let numTotal = asyncFifoQueue.numTotal();
228
+ while ((!this.closing && !this.paused) || asyncFifoQueue.numTotal() > 0) {
230
229
  /**
231
230
  * This inner loop tries to fetch jobs concurrently, but if we are waiting for a job
232
231
  * to arrive at the queue we should not try to fetch more jobs (as it would be pointless)
@@ -234,13 +233,12 @@ class Worker extends queue_base_1.QueueBase {
234
233
  while (!this.closing &&
235
234
  !this.paused &&
236
235
  !this.waiting &&
237
- numTotal < this._concurrency &&
236
+ asyncFifoQueue.numTotal() < this._concurrency &&
238
237
  !this.isRateLimited()) {
239
238
  const token = `${this.id}:${tokenPostfix++}`;
240
239
  const fetchedJob = this.retryIfFailed(() => this._getNextJob(client, bclient, token, { block: true }), this.opts.runRetryDelay);
241
240
  asyncFifoQueue.add(fetchedJob);
242
- numTotal = asyncFifoQueue.numTotal();
243
- if (this.waiting && numTotal > 1) {
241
+ if (this.waiting && asyncFifoQueue.numTotal() > 1) {
244
242
  // We are waiting for jobs but we have others that we could start processing already
245
243
  break;
246
244
  }
@@ -248,7 +246,7 @@ class Worker extends queue_base_1.QueueBase {
248
246
  // to Redis in high concurrency scenarios.
249
247
  const job = await fetchedJob;
250
248
  // No more jobs waiting but we have others that could start processing already
251
- if (!job && numTotal > 1) {
249
+ if (!job && asyncFifoQueue.numTotal() > 1) {
252
250
  break;
253
251
  }
254
252
  // If there are potential jobs to be processed and blockUntil is set, we should exit to avoid waiting
@@ -271,7 +269,6 @@ class Worker extends queue_base_1.QueueBase {
271
269
  await this.waitForRateLimit();
272
270
  }
273
271
  }
274
- return asyncFifoQueue.waitAll();
275
272
  }
276
273
  /**
277
274
  * Returns a promise that resolves to the next job in queue.
@@ -464,7 +461,7 @@ class Worker extends queue_base_1.QueueBase {
464
461
  // Add next scheduled job if necessary.
465
462
  if (job.opts.repeat && !job.nextRepeatableJobId) {
466
463
  // Use new job scheduler if possible
467
- if (job.repeatJobKey) {
464
+ if (job.repeatJobKey && job.repeatJobKey.split(':').length < 5) {
468
465
  const jobScheduler = await this.jobScheduler;
469
466
  await jobScheduler.upsertJobScheduler(job.repeatJobKey, job.opts.repeat, job.name, job.data, job.opts, { override: false, producerId: job.id });
470
467
  }
@@ -576,7 +573,9 @@ class Worker extends queue_base_1.QueueBase {
576
573
  });
577
574
  if (!this.paused) {
578
575
  this.paused = true;
579
- await (!doNotWaitActive && this.whenCurrentJobsFinished());
576
+ if (!doNotWaitActive) {
577
+ await this.whenCurrentJobsFinished();
578
+ }
580
579
  (_a = this.stalledCheckStopper) === null || _a === void 0 ? void 0 : _a.call(this);
581
580
  this.emit('paused');
582
581
  }
@@ -0,0 +1,15 @@
1
+ --[[
2
+ Function to move job to wait to be picked up by a waiting worker.
3
+ ]]
4
+
5
+ -- Includes
6
+ --- @include "addJobInTargetList"
7
+ --- @include "getTargetQueueList"
8
+
9
+ local function moveJobToWait(metaKey, activeKey, waitKey, pausedKey, markerKey, eventStreamKey,
10
+ jobId, pushCmd)
11
+ local target, isPausedOrMaxed = getTargetQueueList(metaKey, activeKey, waitKey, pausedKey)
12
+ addJobInTargetList(target, markerKey, pushCmd, isPausedOrMaxed, jobId)
13
+
14
+ rcall("XADD", eventStreamKey, "*", "event", "waiting", "jobId", jobId, 'prev', 'active')
15
+ end
@@ -29,6 +29,10 @@ local jobId = ARGV[1]
29
29
  local token = ARGV[2]
30
30
  local jobKey = ARGV[3]
31
31
 
32
+ if rcall("EXISTS", jobKey) == 0 then
33
+ return -1
34
+ end
35
+
32
36
  local errorCode = removeLock(jobKey, KEYS[3], token, jobId)
33
37
  if errorCode < 0 then
34
38
  return errorCode
@@ -60,4 +64,4 @@ if pttl > 0 then
60
64
  return pttl
61
65
  else
62
66
  return 0
63
- end
67
+ end
@@ -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