power-queues 2.0.8 → 2.0.10
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.
- package/dist/index.cjs +25 -34
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +35 -35
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -270,7 +270,7 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
|
|
|
270
270
|
this.removeOnExecuted = false;
|
|
271
271
|
this.executeBatchAtOnce = false;
|
|
272
272
|
this.executeJobStatus = false;
|
|
273
|
-
this.
|
|
273
|
+
this.executeJobStatusTtlMs = 300;
|
|
274
274
|
this.consumerHost = "host";
|
|
275
275
|
this.stream = "stream";
|
|
276
276
|
this.group = "group";
|
|
@@ -305,13 +305,13 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
|
|
|
305
305
|
while (!signal?.aborted) {
|
|
306
306
|
try {
|
|
307
307
|
const tasks = await this.select();
|
|
308
|
-
if (!
|
|
308
|
+
if (!(0, import_full_utils.isArrFilled)(tasks)) {
|
|
309
309
|
await (0, import_full_utils.wait)(600);
|
|
310
310
|
continue;
|
|
311
311
|
}
|
|
312
312
|
const tasksP = await this.onSelected(tasks);
|
|
313
|
-
const ids = await this.execute(
|
|
314
|
-
if (
|
|
313
|
+
const ids = await this.execute((0, import_full_utils.isArrFilled)(tasksP) ? tasksP : tasks);
|
|
314
|
+
if ((0, import_full_utils.isArrFilled)(tasks)) {
|
|
315
315
|
await this.approve(ids);
|
|
316
316
|
}
|
|
317
317
|
} catch (err) {
|
|
@@ -321,10 +321,10 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
|
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
323
|
async addTasks(queueName, data, opts = {}) {
|
|
324
|
-
if (!
|
|
324
|
+
if (!(0, import_full_utils.isArrFilled)(data)) {
|
|
325
325
|
throw new Error("Tasks is not filled.");
|
|
326
326
|
}
|
|
327
|
-
if (
|
|
327
|
+
if (!(0, import_full_utils.isStrFilled)(queueName)) {
|
|
328
328
|
throw new Error("Queue name is required.");
|
|
329
329
|
}
|
|
330
330
|
const job = (0, import_uuid.v4)();
|
|
@@ -353,13 +353,7 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
|
|
|
353
353
|
});
|
|
354
354
|
if (opts.status) {
|
|
355
355
|
await this.redis.set(`${queueName}:${job}:total`, data.length);
|
|
356
|
-
await this.redis.
|
|
357
|
-
await this.redis.set(`${queueName}:${job}:err`, 0);
|
|
358
|
-
await this.redis.set(`${queueName}:${job}:ok`, 0);
|
|
359
|
-
await this.redis.pexpire(`${queueName}:${job}:total`, opts.statusTimeoutMs || 864e5);
|
|
360
|
-
await this.redis.pexpire(`${queueName}:${job}:ready`, opts.statusTimeoutMs || 864e5);
|
|
361
|
-
await this.redis.pexpire(`${queueName}:${job}:err`, opts.statusTimeoutMs || 864e5);
|
|
362
|
-
await this.redis.pexpire(`${queueName}:${job}:ok`, opts.statusTimeoutMs || 864e5);
|
|
356
|
+
await this.redis.pexpire(`${queueName}:${job}:total`, opts.statusTimeoutMs || 3e5);
|
|
363
357
|
}
|
|
364
358
|
await Promise.all(runners);
|
|
365
359
|
return result;
|
|
@@ -394,7 +388,7 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
|
|
|
394
388
|
throw new Error("Load lua script failed.");
|
|
395
389
|
}
|
|
396
390
|
saveScript(name, codeBody) {
|
|
397
|
-
if (
|
|
391
|
+
if (!(0, import_full_utils.isStrFilled)(codeBody)) {
|
|
398
392
|
throw new Error("Script body is empty.");
|
|
399
393
|
}
|
|
400
394
|
this.scripts[name] = { codeBody };
|
|
@@ -402,7 +396,7 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
|
|
|
402
396
|
}
|
|
403
397
|
async runScript(name, keys, args, defaultCode) {
|
|
404
398
|
if (!this.scripts[name]) {
|
|
405
|
-
if (
|
|
399
|
+
if (!(0, import_full_utils.isStrFilled)(defaultCode)) {
|
|
406
400
|
throw new Error(`Undefined script "${name}". Save it before executing.`);
|
|
407
401
|
}
|
|
408
402
|
this.saveScript(name, defaultCode);
|
|
@@ -445,12 +439,12 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
|
|
|
445
439
|
const entry = item;
|
|
446
440
|
const id = entry.id ?? "*";
|
|
447
441
|
let flat;
|
|
448
|
-
if ("flat" in entry &&
|
|
442
|
+
if ("flat" in entry && (0, import_full_utils.isArrFilled)(entry.flat)) {
|
|
449
443
|
flat = entry.flat;
|
|
450
444
|
if (flat.length % 2 !== 0) {
|
|
451
445
|
throw new Error('Property "flat" must contain an even number of realKeysLength (field/value pairs).');
|
|
452
446
|
}
|
|
453
|
-
} else if ("payload" in entry &&
|
|
447
|
+
} else if ("payload" in entry && (0, import_full_utils.isObjFilled)(entry.payload)) {
|
|
454
448
|
flat = [];
|
|
455
449
|
for (const [k, v] of Object.entries(entry.payload)) {
|
|
456
450
|
flat.push(k, v);
|
|
@@ -459,13 +453,13 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
|
|
|
459
453
|
throw new Error('Task must have "payload" or "flat".');
|
|
460
454
|
}
|
|
461
455
|
const pairs = flat.length / 2;
|
|
462
|
-
if (
|
|
456
|
+
if ((0, import_full_utils.isNumNZ)(pairs)) {
|
|
463
457
|
throw new Error('Task must have "payload" or "flat".');
|
|
464
458
|
}
|
|
465
459
|
argv.push(String(id));
|
|
466
460
|
argv.push(String(pairs));
|
|
467
461
|
for (const token of flat) {
|
|
468
|
-
argv.push(!token ? "" :
|
|
462
|
+
argv.push(!token ? "" : (0, import_full_utils.isStrFilled)(token) ? token : String(token));
|
|
469
463
|
}
|
|
470
464
|
}
|
|
471
465
|
return argv;
|
|
@@ -476,7 +470,7 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
|
|
|
476
470
|
for (let task of tasks) {
|
|
477
471
|
const createdAt = task?.createdAt || Date.now();
|
|
478
472
|
let entry = task;
|
|
479
|
-
if (
|
|
473
|
+
if ((0, import_full_utils.isObj)(entry.payload)) {
|
|
480
474
|
entry = {
|
|
481
475
|
...entry,
|
|
482
476
|
payload: {
|
|
@@ -545,8 +539,8 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
|
|
|
545
539
|
async success(id, payload, createdAt, job, key) {
|
|
546
540
|
if (this.executeJobStatus) {
|
|
547
541
|
const prefix = `${this.stream}:${job}:`;
|
|
548
|
-
|
|
549
|
-
await this.
|
|
542
|
+
await this.incr(`${prefix}ok`, this.executeJobStatusTtlMs);
|
|
543
|
+
await this.incr(`${prefix}ready`, this.executeJobStatusTtlMs);
|
|
550
544
|
}
|
|
551
545
|
await this.onSuccess(id, payload, createdAt, job, key);
|
|
552
546
|
}
|
|
@@ -556,8 +550,8 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
|
|
|
556
550
|
async error(err, id, payload, createdAt, job, key, attempt) {
|
|
557
551
|
if (this.executeJobStatus && attempt >= this.workerMaxRetries) {
|
|
558
552
|
const prefix = `${this.stream}:${job}:`;
|
|
559
|
-
|
|
560
|
-
await this.
|
|
553
|
+
await this.incr(`${prefix}err`, this.executeJobStatusTtlMs);
|
|
554
|
+
await this.incr(`${prefix}ready`, this.executeJobStatusTtlMs);
|
|
561
555
|
}
|
|
562
556
|
await this.onError(err, id, payload, createdAt, job, key);
|
|
563
557
|
}
|
|
@@ -591,7 +585,7 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
|
|
|
591
585
|
await Promise.all(promises);
|
|
592
586
|
}
|
|
593
587
|
await this.onExecuted(tasks);
|
|
594
|
-
if ((
|
|
588
|
+
if (!(0, import_full_utils.isArrFilled)(result) && contended > tasks.length >> 1) {
|
|
595
589
|
await this.waitAbortable(15 + Math.floor(Math.random() * 35) + Math.min(250, 15 * contended + Math.floor(Math.random() * 40)));
|
|
596
590
|
}
|
|
597
591
|
} catch (err) {
|
|
@@ -735,7 +729,7 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
|
|
|
735
729
|
}
|
|
736
730
|
async select() {
|
|
737
731
|
let entries = await this.selectStuck();
|
|
738
|
-
if (!entries
|
|
732
|
+
if (!(0, import_full_utils.isArrFilled)(entries)) {
|
|
739
733
|
entries = await this.selectFresh();
|
|
740
734
|
}
|
|
741
735
|
return this.normalizeEntries(entries);
|
|
@@ -743,7 +737,7 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
|
|
|
743
737
|
async selectStuck() {
|
|
744
738
|
try {
|
|
745
739
|
const res = await this.runScript("SelectStuck", [this.stream], [this.group, this.consumer(), String(this.recoveryStuckTasksTimeoutMs), String(this.workerBatchTasksCount), String(this.workerSelectionTimeoutMs)], SelectStuck);
|
|
746
|
-
return
|
|
740
|
+
return (0, import_full_utils.isArr)(res) ? res : [];
|
|
747
741
|
} catch (err) {
|
|
748
742
|
if (String(err?.message || "").includes("NOGROUP")) {
|
|
749
743
|
await this.createGroup();
|
|
@@ -766,11 +760,8 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
|
|
|
766
760
|
this.stream,
|
|
767
761
|
">"
|
|
768
762
|
);
|
|
769
|
-
if (!res?.[0]?.[1]?.length) {
|
|
770
|
-
return [];
|
|
771
|
-
}
|
|
772
763
|
entries = res?.[0]?.[1] ?? [];
|
|
773
|
-
if (!entries
|
|
764
|
+
if (!(0, import_full_utils.isArrFilled)(entries)) {
|
|
774
765
|
return [];
|
|
775
766
|
}
|
|
776
767
|
} catch (err) {
|
|
@@ -847,9 +838,9 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
|
|
|
847
838
|
return Array.from(raw || []).map((e) => {
|
|
848
839
|
const id = Buffer.isBuffer(e?.[0]) ? e[0].toString() : e?.[0];
|
|
849
840
|
const kvRaw = e?.[1] ?? [];
|
|
850
|
-
const kv =
|
|
841
|
+
const kv = (0, import_full_utils.isArr)(kvRaw) ? kvRaw.map((x) => Buffer.isBuffer(x) ? x.toString() : x) : [];
|
|
851
842
|
return [id, kv];
|
|
852
|
-
}).filter(([id, kv]) =>
|
|
843
|
+
}).filter(([id, kv]) => (0, import_full_utils.isStrFilled)(id) && (0, import_full_utils.isArr)(kv) && (kv.length & 1) === 0).map(([id, kv]) => {
|
|
853
844
|
const { idemKey = "", job, createdAt, payload } = this.values(kv);
|
|
854
845
|
return [id, this.payload(payload), createdAt, job, idemKey];
|
|
855
846
|
});
|
|
@@ -863,7 +854,7 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
|
|
|
863
854
|
}
|
|
864
855
|
payload(data) {
|
|
865
856
|
try {
|
|
866
|
-
return
|
|
857
|
+
return (0, import_full_utils.jsonDecode)(data);
|
|
867
858
|
} catch (err) {
|
|
868
859
|
}
|
|
869
860
|
return data;
|
package/dist/index.d.cts
CHANGED
|
@@ -44,7 +44,7 @@ declare class PowerQueues extends PowerRedis {
|
|
|
44
44
|
readonly removeOnExecuted: boolean;
|
|
45
45
|
readonly executeBatchAtOnce: boolean;
|
|
46
46
|
readonly executeJobStatus: boolean;
|
|
47
|
-
readonly
|
|
47
|
+
readonly executeJobStatusTtlMs: number;
|
|
48
48
|
readonly consumerHost: string;
|
|
49
49
|
readonly stream: string;
|
|
50
50
|
readonly group: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ declare class PowerQueues extends PowerRedis {
|
|
|
44
44
|
readonly removeOnExecuted: boolean;
|
|
45
45
|
readonly executeBatchAtOnce: boolean;
|
|
46
46
|
readonly executeJobStatus: boolean;
|
|
47
|
-
readonly
|
|
47
|
+
readonly executeJobStatusTtlMs: number;
|
|
48
48
|
readonly consumerHost: string;
|
|
49
49
|
readonly stream: string;
|
|
50
50
|
readonly group: string;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
// src/PowerQueues.ts
|
|
2
2
|
import { PowerRedis } from "power-redis";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
isObjFilled,
|
|
5
|
+
isObj,
|
|
6
|
+
isArrFilled,
|
|
7
|
+
isArr,
|
|
8
|
+
isStrFilled,
|
|
9
|
+
isNumNZ,
|
|
10
|
+
jsonDecode,
|
|
11
|
+
wait
|
|
12
|
+
} from "full-utils";
|
|
4
13
|
import { v4 as uuid } from "uuid";
|
|
5
14
|
|
|
6
15
|
// src/scripts.ts
|
|
@@ -244,7 +253,7 @@ var PowerQueues = class extends PowerRedis {
|
|
|
244
253
|
this.removeOnExecuted = false;
|
|
245
254
|
this.executeBatchAtOnce = false;
|
|
246
255
|
this.executeJobStatus = false;
|
|
247
|
-
this.
|
|
256
|
+
this.executeJobStatusTtlMs = 300;
|
|
248
257
|
this.consumerHost = "host";
|
|
249
258
|
this.stream = "stream";
|
|
250
259
|
this.group = "group";
|
|
@@ -279,13 +288,13 @@ var PowerQueues = class extends PowerRedis {
|
|
|
279
288
|
while (!signal?.aborted) {
|
|
280
289
|
try {
|
|
281
290
|
const tasks = await this.select();
|
|
282
|
-
if (!
|
|
291
|
+
if (!isArrFilled(tasks)) {
|
|
283
292
|
await wait(600);
|
|
284
293
|
continue;
|
|
285
294
|
}
|
|
286
295
|
const tasksP = await this.onSelected(tasks);
|
|
287
|
-
const ids = await this.execute(
|
|
288
|
-
if (
|
|
296
|
+
const ids = await this.execute(isArrFilled(tasksP) ? tasksP : tasks);
|
|
297
|
+
if (isArrFilled(tasks)) {
|
|
289
298
|
await this.approve(ids);
|
|
290
299
|
}
|
|
291
300
|
} catch (err) {
|
|
@@ -295,10 +304,10 @@ var PowerQueues = class extends PowerRedis {
|
|
|
295
304
|
}
|
|
296
305
|
}
|
|
297
306
|
async addTasks(queueName, data, opts = {}) {
|
|
298
|
-
if (!
|
|
307
|
+
if (!isArrFilled(data)) {
|
|
299
308
|
throw new Error("Tasks is not filled.");
|
|
300
309
|
}
|
|
301
|
-
if (
|
|
310
|
+
if (!isStrFilled(queueName)) {
|
|
302
311
|
throw new Error("Queue name is required.");
|
|
303
312
|
}
|
|
304
313
|
const job = uuid();
|
|
@@ -327,13 +336,7 @@ var PowerQueues = class extends PowerRedis {
|
|
|
327
336
|
});
|
|
328
337
|
if (opts.status) {
|
|
329
338
|
await this.redis.set(`${queueName}:${job}:total`, data.length);
|
|
330
|
-
await this.redis.
|
|
331
|
-
await this.redis.set(`${queueName}:${job}:err`, 0);
|
|
332
|
-
await this.redis.set(`${queueName}:${job}:ok`, 0);
|
|
333
|
-
await this.redis.pexpire(`${queueName}:${job}:total`, opts.statusTimeoutMs || 864e5);
|
|
334
|
-
await this.redis.pexpire(`${queueName}:${job}:ready`, opts.statusTimeoutMs || 864e5);
|
|
335
|
-
await this.redis.pexpire(`${queueName}:${job}:err`, opts.statusTimeoutMs || 864e5);
|
|
336
|
-
await this.redis.pexpire(`${queueName}:${job}:ok`, opts.statusTimeoutMs || 864e5);
|
|
339
|
+
await this.redis.pexpire(`${queueName}:${job}:total`, opts.statusTimeoutMs || 3e5);
|
|
337
340
|
}
|
|
338
341
|
await Promise.all(runners);
|
|
339
342
|
return result;
|
|
@@ -368,7 +371,7 @@ var PowerQueues = class extends PowerRedis {
|
|
|
368
371
|
throw new Error("Load lua script failed.");
|
|
369
372
|
}
|
|
370
373
|
saveScript(name, codeBody) {
|
|
371
|
-
if (
|
|
374
|
+
if (!isStrFilled(codeBody)) {
|
|
372
375
|
throw new Error("Script body is empty.");
|
|
373
376
|
}
|
|
374
377
|
this.scripts[name] = { codeBody };
|
|
@@ -376,7 +379,7 @@ var PowerQueues = class extends PowerRedis {
|
|
|
376
379
|
}
|
|
377
380
|
async runScript(name, keys, args, defaultCode) {
|
|
378
381
|
if (!this.scripts[name]) {
|
|
379
|
-
if (
|
|
382
|
+
if (!isStrFilled(defaultCode)) {
|
|
380
383
|
throw new Error(`Undefined script "${name}". Save it before executing.`);
|
|
381
384
|
}
|
|
382
385
|
this.saveScript(name, defaultCode);
|
|
@@ -419,12 +422,12 @@ var PowerQueues = class extends PowerRedis {
|
|
|
419
422
|
const entry = item;
|
|
420
423
|
const id = entry.id ?? "*";
|
|
421
424
|
let flat;
|
|
422
|
-
if ("flat" in entry &&
|
|
425
|
+
if ("flat" in entry && isArrFilled(entry.flat)) {
|
|
423
426
|
flat = entry.flat;
|
|
424
427
|
if (flat.length % 2 !== 0) {
|
|
425
428
|
throw new Error('Property "flat" must contain an even number of realKeysLength (field/value pairs).');
|
|
426
429
|
}
|
|
427
|
-
} else if ("payload" in entry &&
|
|
430
|
+
} else if ("payload" in entry && isObjFilled(entry.payload)) {
|
|
428
431
|
flat = [];
|
|
429
432
|
for (const [k, v] of Object.entries(entry.payload)) {
|
|
430
433
|
flat.push(k, v);
|
|
@@ -433,13 +436,13 @@ var PowerQueues = class extends PowerRedis {
|
|
|
433
436
|
throw new Error('Task must have "payload" or "flat".');
|
|
434
437
|
}
|
|
435
438
|
const pairs = flat.length / 2;
|
|
436
|
-
if (pairs
|
|
439
|
+
if (isNumNZ(pairs)) {
|
|
437
440
|
throw new Error('Task must have "payload" or "flat".');
|
|
438
441
|
}
|
|
439
442
|
argv.push(String(id));
|
|
440
443
|
argv.push(String(pairs));
|
|
441
444
|
for (const token of flat) {
|
|
442
|
-
argv.push(!token ? "" :
|
|
445
|
+
argv.push(!token ? "" : isStrFilled(token) ? token : String(token));
|
|
443
446
|
}
|
|
444
447
|
}
|
|
445
448
|
return argv;
|
|
@@ -450,7 +453,7 @@ var PowerQueues = class extends PowerRedis {
|
|
|
450
453
|
for (let task of tasks) {
|
|
451
454
|
const createdAt = task?.createdAt || Date.now();
|
|
452
455
|
let entry = task;
|
|
453
|
-
if (
|
|
456
|
+
if (isObj(entry.payload)) {
|
|
454
457
|
entry = {
|
|
455
458
|
...entry,
|
|
456
459
|
payload: {
|
|
@@ -519,8 +522,8 @@ var PowerQueues = class extends PowerRedis {
|
|
|
519
522
|
async success(id, payload, createdAt, job, key) {
|
|
520
523
|
if (this.executeJobStatus) {
|
|
521
524
|
const prefix = `${this.stream}:${job}:`;
|
|
522
|
-
|
|
523
|
-
await this.
|
|
525
|
+
await this.incr(`${prefix}ok`, this.executeJobStatusTtlMs);
|
|
526
|
+
await this.incr(`${prefix}ready`, this.executeJobStatusTtlMs);
|
|
524
527
|
}
|
|
525
528
|
await this.onSuccess(id, payload, createdAt, job, key);
|
|
526
529
|
}
|
|
@@ -530,8 +533,8 @@ var PowerQueues = class extends PowerRedis {
|
|
|
530
533
|
async error(err, id, payload, createdAt, job, key, attempt) {
|
|
531
534
|
if (this.executeJobStatus && attempt >= this.workerMaxRetries) {
|
|
532
535
|
const prefix = `${this.stream}:${job}:`;
|
|
533
|
-
|
|
534
|
-
await this.
|
|
536
|
+
await this.incr(`${prefix}err`, this.executeJobStatusTtlMs);
|
|
537
|
+
await this.incr(`${prefix}ready`, this.executeJobStatusTtlMs);
|
|
535
538
|
}
|
|
536
539
|
await this.onError(err, id, payload, createdAt, job, key);
|
|
537
540
|
}
|
|
@@ -565,7 +568,7 @@ var PowerQueues = class extends PowerRedis {
|
|
|
565
568
|
await Promise.all(promises);
|
|
566
569
|
}
|
|
567
570
|
await this.onExecuted(tasks);
|
|
568
|
-
if (
|
|
571
|
+
if (!isArrFilled(result) && contended > tasks.length >> 1) {
|
|
569
572
|
await this.waitAbortable(15 + Math.floor(Math.random() * 35) + Math.min(250, 15 * contended + Math.floor(Math.random() * 40)));
|
|
570
573
|
}
|
|
571
574
|
} catch (err) {
|
|
@@ -709,7 +712,7 @@ var PowerQueues = class extends PowerRedis {
|
|
|
709
712
|
}
|
|
710
713
|
async select() {
|
|
711
714
|
let entries = await this.selectStuck();
|
|
712
|
-
if (!entries
|
|
715
|
+
if (!isArrFilled(entries)) {
|
|
713
716
|
entries = await this.selectFresh();
|
|
714
717
|
}
|
|
715
718
|
return this.normalizeEntries(entries);
|
|
@@ -717,7 +720,7 @@ var PowerQueues = class extends PowerRedis {
|
|
|
717
720
|
async selectStuck() {
|
|
718
721
|
try {
|
|
719
722
|
const res = await this.runScript("SelectStuck", [this.stream], [this.group, this.consumer(), String(this.recoveryStuckTasksTimeoutMs), String(this.workerBatchTasksCount), String(this.workerSelectionTimeoutMs)], SelectStuck);
|
|
720
|
-
return
|
|
723
|
+
return isArr(res) ? res : [];
|
|
721
724
|
} catch (err) {
|
|
722
725
|
if (String(err?.message || "").includes("NOGROUP")) {
|
|
723
726
|
await this.createGroup();
|
|
@@ -740,11 +743,8 @@ var PowerQueues = class extends PowerRedis {
|
|
|
740
743
|
this.stream,
|
|
741
744
|
">"
|
|
742
745
|
);
|
|
743
|
-
if (!res?.[0]?.[1]?.length) {
|
|
744
|
-
return [];
|
|
745
|
-
}
|
|
746
746
|
entries = res?.[0]?.[1] ?? [];
|
|
747
|
-
if (!entries
|
|
747
|
+
if (!isArrFilled(entries)) {
|
|
748
748
|
return [];
|
|
749
749
|
}
|
|
750
750
|
} catch (err) {
|
|
@@ -821,9 +821,9 @@ var PowerQueues = class extends PowerRedis {
|
|
|
821
821
|
return Array.from(raw || []).map((e) => {
|
|
822
822
|
const id = Buffer.isBuffer(e?.[0]) ? e[0].toString() : e?.[0];
|
|
823
823
|
const kvRaw = e?.[1] ?? [];
|
|
824
|
-
const kv =
|
|
824
|
+
const kv = isArr(kvRaw) ? kvRaw.map((x) => Buffer.isBuffer(x) ? x.toString() : x) : [];
|
|
825
825
|
return [id, kv];
|
|
826
|
-
}).filter(([id, kv]) =>
|
|
826
|
+
}).filter(([id, kv]) => isStrFilled(id) && isArr(kv) && (kv.length & 1) === 0).map(([id, kv]) => {
|
|
827
827
|
const { idemKey = "", job, createdAt, payload } = this.values(kv);
|
|
828
828
|
return [id, this.payload(payload), createdAt, job, idemKey];
|
|
829
829
|
});
|
|
@@ -837,7 +837,7 @@ var PowerQueues = class extends PowerRedis {
|
|
|
837
837
|
}
|
|
838
838
|
payload(data) {
|
|
839
839
|
try {
|
|
840
|
-
return
|
|
840
|
+
return jsonDecode(data);
|
|
841
841
|
} catch (err) {
|
|
842
842
|
}
|
|
843
843
|
return data;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "power-queues",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.10",
|
|
4
4
|
"description": "Base classes for implementing custom queues in redis under high load conditions based on nestjs.",
|
|
5
5
|
"author": "ihor-bielchenko",
|
|
6
6
|
"license": "MIT",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"@nestjs/common": "^11.1.8",
|
|
86
86
|
"full-utils": "^2.0.3",
|
|
87
87
|
"ioredis": "^5.8.2",
|
|
88
|
-
"power-redis": "^2.0.
|
|
88
|
+
"power-redis": "^2.0.6",
|
|
89
89
|
"uuid": "^13.0.0"
|
|
90
90
|
}
|
|
91
91
|
}
|