@portqueue/core 1.2.1 → 1.2.3
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/conformance/index.cjs +82 -2
- package/dist/conformance/index.cjs.map +1 -1
- package/dist/conformance/index.mjs +83 -3
- package/dist/conformance/index.mjs.map +1 -1
- package/dist/consumer/completion-batcher.d.ts +29 -0
- package/dist/consumer/completion.service.d.ts +5 -3
- package/dist/consumer/execution.service.d.ts +7 -2
- package/dist/consumer/worker.d.ts +16 -0
- package/dist/drivers/driver.interface.d.ts +26 -2
- package/dist/drivers/mysql/index.cjs +50 -3
- package/dist/drivers/mysql/index.cjs.map +1 -1
- package/dist/drivers/mysql/index.mjs +50 -3
- package/dist/drivers/mysql/index.mjs.map +1 -1
- package/dist/drivers/mysql/mysql-driver.d.ts +16 -3
- package/dist/drivers/oracle/index.cjs +50 -3
- package/dist/drivers/oracle/index.cjs.map +1 -1
- package/dist/drivers/oracle/index.mjs +50 -3
- package/dist/drivers/oracle/index.mjs.map +1 -1
- package/dist/drivers/oracle/oracle-driver.d.ts +14 -3
- package/dist/drivers/pglite/index.cjs +6 -3
- package/dist/drivers/pglite/index.cjs.map +1 -1
- package/dist/drivers/pglite/index.mjs +6 -3
- package/dist/drivers/pglite/index.mjs.map +1 -1
- package/dist/drivers/pglite/migrations.d.ts +2 -3
- package/dist/drivers/postgresql/index.cjs +1 -1
- package/dist/drivers/postgresql/index.mjs +1 -1
- package/dist/drivers/postgresql/migrations.d.ts +21 -0
- package/dist/drivers/postgresql/postgresql-driver.d.ts +28 -3
- package/dist/drivers/shared/base-driver.d.ts +28 -2
- package/dist/drivers/sqlite/index.cjs +36 -4
- package/dist/drivers/sqlite/index.cjs.map +1 -1
- package/dist/drivers/sqlite/index.mjs +36 -4
- package/dist/drivers/sqlite/index.mjs.map +1 -1
- package/dist/drivers/sqlite/sqlite-driver.d.ts +14 -3
- package/dist/index.cjs +107 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +108 -11
- package/dist/index.mjs.map +1 -1
- package/dist/jobs/job-record.d.ts +8 -0
- package/dist/{migration-Dx8eUthW.cjs → migration-CX7j4wVB.cjs} +59 -1
- package/dist/migration-CX7j4wVB.cjs.map +1 -0
- package/dist/{migration-D0IRP2oq.js → migration-VkNQT3a_.js} +60 -2
- package/dist/migration-VkNQT3a_.js.map +1 -0
- package/dist/{postgresql-driver-CPHv5SUT.js → postgresql-driver-DQRzg2NA.js} +179 -57
- package/dist/postgresql-driver-DQRzg2NA.js.map +1 -0
- package/dist/{postgresql-driver-DRT68TKb.cjs → postgresql-driver-xfqy9mi8.cjs} +179 -57
- package/dist/postgresql-driver-xfqy9mi8.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/migration-D0IRP2oq.js.map +0 -1
- package/dist/migration-Dx8eUthW.cjs.map +0 -1
- package/dist/postgresql-driver-CPHv5SUT.js.map +0 -1
- package/dist/postgresql-driver-DRT68TKb.cjs.map +0 -1
|
@@ -24,7 +24,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
25
25
|
const node_crypto = require("node:crypto");
|
|
26
26
|
const storage_constants = require("../../storage.constants-BKeXcSQe.cjs");
|
|
27
|
-
const migration = require("../../migration-
|
|
27
|
+
const migration = require("../../migration-CX7j4wVB.cjs");
|
|
28
28
|
function v1(names) {
|
|
29
29
|
const t = names.name;
|
|
30
30
|
const idx = names.derived;
|
|
@@ -596,11 +596,11 @@ class MysqlDriver extends migration.BaseDriver {
|
|
|
596
596
|
session
|
|
597
597
|
);
|
|
598
598
|
const res = await this.execute(
|
|
599
|
-
`SELECT ${migration.
|
|
599
|
+
`SELECT ${migration.CLAIM_COLUMNS.join(", ")} FROM ${this.t(migration.TableName.JOB)} WHERE ${migration.JobColumn.ID} IN (${this.phList(ids.length)}) AND ${migration.JobColumn.LOCK_TOKEN} = ${this.ph(ids.length)}`,
|
|
600
600
|
[...ids, lockToken],
|
|
601
601
|
session
|
|
602
602
|
);
|
|
603
|
-
return this.sortClaimed(res.rows.map((r) => this.
|
|
603
|
+
return this.sortClaimed(res.rows.map((r) => this.mapClaimedJob(r, { queueName, lockToken })));
|
|
604
604
|
});
|
|
605
605
|
}
|
|
606
606
|
/**
|
|
@@ -648,6 +648,53 @@ class MysqlDriver extends migration.BaseDriver {
|
|
|
648
648
|
);
|
|
649
649
|
return res.rowCount > 0;
|
|
650
650
|
}
|
|
651
|
+
/**
|
|
652
|
+
* Settle a batch per claim token (and per id chunk). Without `RETURNING`, the rows that still pass
|
|
653
|
+
* the fence (`ACTIVE` and the group's token, exactly like {@link completeJob}) are locked first
|
|
654
|
+
* with `SELECT … FOR UPDATE`, then exactly those are updated — both inside one transaction, so the
|
|
655
|
+
* ids returned are the ids settled. Parameters are pushed in placeholder order.
|
|
656
|
+
*/
|
|
657
|
+
async completeJobs(options) {
|
|
658
|
+
const settled = [];
|
|
659
|
+
for (const group of this.groupByLockToken(options.jobs)) {
|
|
660
|
+
const ids = await this.overIdChunks(
|
|
661
|
+
group.items,
|
|
662
|
+
async (chunk) => this.inTx(options.tx, async (run) => {
|
|
663
|
+
const selParams = chunk.map((job) => job.jobId);
|
|
664
|
+
const sel = await run(
|
|
665
|
+
`SELECT ${migration.JobColumn.ID} FROM ${this.t(migration.TableName.JOB)} WHERE ${migration.JobColumn.ID} IN (${this.phList(chunk.length)})${this.claimFence(selParams, group.lockToken)} FOR UPDATE`,
|
|
666
|
+
selParams
|
|
667
|
+
);
|
|
668
|
+
const held = new Set(sel.rows.map((row) => String(row[migration.JobColumn.ID])));
|
|
669
|
+
const owned = chunk.filter((job) => held.has(job.jobId));
|
|
670
|
+
if (!owned.length) return [];
|
|
671
|
+
const params = [storage_constants.JobStatus.COMPLETED];
|
|
672
|
+
const returnValue = this.returnValueExpression(owned, params);
|
|
673
|
+
const nowAt = params.length;
|
|
674
|
+
params.push(options.now, options.now);
|
|
675
|
+
const idsAt = params.length;
|
|
676
|
+
params.push(...owned.map((job) => job.jobId));
|
|
677
|
+
await run(
|
|
678
|
+
`UPDATE ${this.t(migration.TableName.JOB)} SET ${migration.JobColumn.STATUS} = ${this.ph(0)}, ${migration.JobColumn.RETURN_VALUE} = ${returnValue}, ${migration.JobColumn.COMPLETED_AT} = ${this.ph(nowAt)}, ${migration.JobColumn.UPDATED_AT} = ${this.ph(nowAt + 1)}, ${migration.JobColumn.LOCKED_UNTIL} = NULL, ${migration.JobColumn.LOCK_TOKEN} = NULL WHERE ${migration.JobColumn.ID} IN (${this.phList(owned.length, idsAt)})`,
|
|
679
|
+
params
|
|
680
|
+
);
|
|
681
|
+
return owned.map((job) => job.jobId);
|
|
682
|
+
})
|
|
683
|
+
);
|
|
684
|
+
settled.push(...ids);
|
|
685
|
+
}
|
|
686
|
+
return settled;
|
|
687
|
+
}
|
|
688
|
+
/** `NULL` when no job in the chunk returned anything, otherwise a `CASE` on the id. */
|
|
689
|
+
returnValueExpression(chunk, params) {
|
|
690
|
+
const values = chunk.map((job) => this.toJson(job.returnValue));
|
|
691
|
+
if (values.every((value) => value === null)) return "NULL";
|
|
692
|
+
const arms = chunk.map((job, i) => {
|
|
693
|
+
params.push(job.jobId, values[i]);
|
|
694
|
+
return `WHEN ${this.ph(params.length - 2)} THEN ${this.ph(params.length - 1)}`;
|
|
695
|
+
});
|
|
696
|
+
return `CASE ${migration.JobColumn.ID} ${arms.join(" ")} ELSE NULL END`;
|
|
697
|
+
}
|
|
651
698
|
async retryJob(options) {
|
|
652
699
|
const params = [
|
|
653
700
|
storage_constants.JobStatus.RETRY,
|