@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
|
@@ -2,8 +2,8 @@ import { DatabaseEngine } from '../../options/enums';
|
|
|
2
2
|
import { JobStatus } from '../../jobs/job-state.enum';
|
|
3
3
|
import { DriverCapabilitySet } from '../driver-capabilities';
|
|
4
4
|
import { BaseDriver, RawResult, Session } from '../shared/base-driver';
|
|
5
|
-
import { Driver, DriverProbe, InstanceListFilter, JobListFilter, JobRef, MigrationStep, PageWindow, QueueListFilter, RequeuedJobRef, ScheduleListFilter, ScheduleRef, StalledJobRef, Subscription } from '../driver.interface';
|
|
6
|
-
import { InsertedJobRow, InstanceMetrics, InstanceRow, JobRecord, NewJobRecord, NewScheduleRow, QueueRow, ScheduleRow } from '../../jobs/job-record';
|
|
5
|
+
import { CompletedJobInput, Driver, DriverProbe, InstanceListFilter, JobListFilter, JobRef, MigrationStep, PageWindow, QueueListFilter, RequeuedJobRef, ScheduleListFilter, ScheduleRef, StalledJobRef, Subscription } from '../driver.interface';
|
|
6
|
+
import { ClaimedJob, InsertedJobRow, InstanceMetrics, InstanceRow, JobRecord, NewJobRecord, NewScheduleRow, QueueRow, ScheduleRow } from '../../jobs/job-record';
|
|
7
7
|
import { QueueOptions } from '../../options/queue-options';
|
|
8
8
|
import { TransactionHandle } from '../../tx/transaction-handle';
|
|
9
9
|
export interface MysqlDriverOptions {
|
|
@@ -172,7 +172,7 @@ export declare class MysqlDriver extends BaseDriver implements Driver {
|
|
|
172
172
|
lockDurationSeconds: number;
|
|
173
173
|
now: number;
|
|
174
174
|
instanceKey?: string | null;
|
|
175
|
-
}): Promise<
|
|
175
|
+
}): Promise<ClaimedJob[]>;
|
|
176
176
|
/**
|
|
177
177
|
* The fence a completion is guarded on: the row must still be `ACTIVE` and, when the caller names
|
|
178
178
|
* the claim it is settling, still carry that claim's token.
|
|
@@ -196,6 +196,19 @@ export declare class MysqlDriver extends BaseDriver implements Driver {
|
|
|
196
196
|
lockToken?: string | null;
|
|
197
197
|
tx?: TransactionHandle;
|
|
198
198
|
}): Promise<boolean>;
|
|
199
|
+
/**
|
|
200
|
+
* Settle a batch per claim token (and per id chunk). Without `RETURNING`, the rows that still pass
|
|
201
|
+
* the fence (`ACTIVE` and the group's token, exactly like {@link completeJob}) are locked first
|
|
202
|
+
* with `SELECT … FOR UPDATE`, then exactly those are updated — both inside one transaction, so the
|
|
203
|
+
* ids returned are the ids settled. Parameters are pushed in placeholder order.
|
|
204
|
+
*/
|
|
205
|
+
completeJobs(options: {
|
|
206
|
+
jobs: CompletedJobInput[];
|
|
207
|
+
now: number;
|
|
208
|
+
tx?: TransactionHandle;
|
|
209
|
+
}): Promise<string[]>;
|
|
210
|
+
/** `NULL` when no job in the chunk returned anything, otherwise a `CASE` on the id. */
|
|
211
|
+
private returnValueExpression;
|
|
199
212
|
retryJob(options: {
|
|
200
213
|
jobId: string;
|
|
201
214
|
nextRunAt: number;
|
|
@@ -23,7 +23,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
));
|
|
24
24
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
25
25
|
const storage_constants = require("../../storage.constants-BKeXcSQe.cjs");
|
|
26
|
-
const migration = require("../../migration-
|
|
26
|
+
const migration = require("../../migration-CX7j4wVB.cjs");
|
|
27
27
|
function createIfAbsent(ddl) {
|
|
28
28
|
return `BEGIN
|
|
29
29
|
EXECUTE IMMEDIATE '${ddl.replace(/'/g, "''")}';
|
|
@@ -614,11 +614,11 @@ class OracleDriver extends migration.BaseDriver {
|
|
|
614
614
|
session
|
|
615
615
|
);
|
|
616
616
|
const res = await this.execute(
|
|
617
|
-
`SELECT ${migration.
|
|
617
|
+
`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)}`,
|
|
618
618
|
[...ids, lockToken],
|
|
619
619
|
session
|
|
620
620
|
);
|
|
621
|
-
return this.sortClaimed(res.rows.map((r) => this.
|
|
621
|
+
return this.sortClaimed(res.rows.map((r) => this.mapClaimedJob(r, { queueName, lockToken })));
|
|
622
622
|
});
|
|
623
623
|
}
|
|
624
624
|
/**
|
|
@@ -666,6 +666,53 @@ class OracleDriver extends migration.BaseDriver {
|
|
|
666
666
|
);
|
|
667
667
|
return res.rowCount > 0;
|
|
668
668
|
}
|
|
669
|
+
/**
|
|
670
|
+
* Settle a batch per claim token (and per id chunk). Without `RETURNING`, the rows that still pass
|
|
671
|
+
* the fence (`ACTIVE` and the group's token, exactly like {@link completeJob}) are locked first
|
|
672
|
+
* with `SELECT … FOR UPDATE`, then exactly those are updated — both inside one transaction, so the
|
|
673
|
+
* ids returned are the ids settled. Parameters are pushed in placeholder order.
|
|
674
|
+
*/
|
|
675
|
+
async completeJobs(options) {
|
|
676
|
+
const settled = [];
|
|
677
|
+
for (const group of this.groupByLockToken(options.jobs)) {
|
|
678
|
+
const ids = await this.overIdChunks(
|
|
679
|
+
group.items,
|
|
680
|
+
async (chunk) => this.inTx(options.tx, async (run) => {
|
|
681
|
+
const selParams = chunk.map((job) => job.jobId);
|
|
682
|
+
const sel = await run(
|
|
683
|
+
`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`,
|
|
684
|
+
selParams
|
|
685
|
+
);
|
|
686
|
+
const held = new Set(sel.rows.map((row) => String(row[migration.JobColumn.ID])));
|
|
687
|
+
const owned = chunk.filter((job) => held.has(job.jobId));
|
|
688
|
+
if (!owned.length) return [];
|
|
689
|
+
const valued = owned.filter((job) => this.toJson(job.returnValue) !== null);
|
|
690
|
+
const bare = owned.filter((job) => this.toJson(job.returnValue) === null);
|
|
691
|
+
if (bare.length) {
|
|
692
|
+
await run(
|
|
693
|
+
`UPDATE ${this.t(migration.TableName.JOB)} SET ${migration.JobColumn.STATUS} = ${this.ph(0)}, ${migration.JobColumn.RETURN_VALUE} = NULL, ${migration.JobColumn.COMPLETED_AT} = ${this.ph(1)}, ${migration.JobColumn.UPDATED_AT} = ${this.ph(2)}, ${migration.JobColumn.LOCKED_UNTIL} = NULL, ${migration.JobColumn.LOCK_TOKEN} = NULL WHERE ${migration.JobColumn.ID} IN (${this.phList(bare.length, 3)})`,
|
|
694
|
+
[storage_constants.JobStatus.COMPLETED, options.now, options.now, ...bare.map((job) => job.jobId)]
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
for (const job of valued) {
|
|
698
|
+
await run(
|
|
699
|
+
`UPDATE ${this.t(migration.TableName.JOB)} SET ${migration.JobColumn.STATUS} = ${this.ph(0)}, ${migration.JobColumn.RETURN_VALUE} = ${this.ph(1)}, ${migration.JobColumn.COMPLETED_AT} = ${this.ph(2)}, ${migration.JobColumn.UPDATED_AT} = ${this.ph(3)}, ${migration.JobColumn.LOCKED_UNTIL} = NULL, ${migration.JobColumn.LOCK_TOKEN} = NULL WHERE ${migration.JobColumn.ID} = ${this.ph(4)}`,
|
|
700
|
+
[
|
|
701
|
+
storage_constants.JobStatus.COMPLETED,
|
|
702
|
+
this.toJson(job.returnValue),
|
|
703
|
+
options.now,
|
|
704
|
+
options.now,
|
|
705
|
+
job.jobId
|
|
706
|
+
]
|
|
707
|
+
);
|
|
708
|
+
}
|
|
709
|
+
return owned.map((job) => job.jobId);
|
|
710
|
+
})
|
|
711
|
+
);
|
|
712
|
+
settled.push(...ids);
|
|
713
|
+
}
|
|
714
|
+
return settled;
|
|
715
|
+
}
|
|
669
716
|
async retryJob(options) {
|
|
670
717
|
const params = [
|
|
671
718
|
storage_constants.JobStatus.RETRY,
|