@portqueue/core 1.0.3 → 1.1.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.
- package/dist/conformance/index.cjs +70 -1
- package/dist/conformance/index.cjs.map +1 -1
- package/dist/conformance/index.d.ts +4 -2
- package/dist/conformance/index.mjs +70 -1
- package/dist/conformance/index.mjs.map +1 -1
- package/dist/constants/job.constants.d.ts +3 -1
- package/dist/constants/storage.constants.d.ts +8 -0
- package/dist/constants/time.constants.d.ts +13 -0
- package/dist/constants/worker.constants.d.ts +5 -0
- package/dist/drivers/driver.interface.d.ts +47 -0
- package/dist/drivers/mysql/index.cjs +169 -76
- package/dist/drivers/mysql/index.cjs.map +1 -1
- package/dist/drivers/mysql/index.mjs +169 -76
- package/dist/drivers/mysql/index.mjs.map +1 -1
- package/dist/drivers/mysql/mysql-driver.d.ts +42 -19
- package/dist/drivers/oracle/index.cjs +144 -65
- package/dist/drivers/oracle/index.cjs.map +1 -1
- package/dist/drivers/oracle/index.mjs +144 -65
- package/dist/drivers/oracle/index.mjs.map +1 -1
- package/dist/drivers/oracle/oracle-driver.d.ts +34 -15
- package/dist/drivers/pglite/index.cjs +3 -3
- package/dist/drivers/pglite/index.mjs +3 -3
- package/dist/drivers/postgresql/index.cjs +1 -1
- package/dist/drivers/postgresql/index.mjs +1 -1
- package/dist/drivers/postgresql/postgresql-driver.d.ts +33 -7
- package/dist/drivers/shared/base-driver.d.ts +2 -0
- package/dist/drivers/shared/migration-runner.service.d.ts +19 -4
- package/dist/drivers/shared/migration.d.ts +5 -3
- package/dist/drivers/sqlite/index.cjs +113 -42
- package/dist/drivers/sqlite/index.cjs.map +1 -1
- package/dist/drivers/sqlite/index.mjs +113 -42
- package/dist/drivers/sqlite/index.mjs.map +1 -1
- package/dist/drivers/sqlite/sqlite-driver.d.ts +26 -0
- package/dist/drivers/table-names.d.ts +3 -2
- package/dist/index.cjs +519 -316
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +521 -318
- package/dist/index.mjs.map +1 -1
- package/dist/{migration-D73ANkYV.js → migration-D0IRP2oq.js} +6 -2
- package/dist/migration-D0IRP2oq.js.map +1 -0
- package/dist/{migration-CoTjpgBl.cjs → migration-Dx8eUthW.cjs} +6 -2
- package/dist/migration-Dx8eUthW.cjs.map +1 -0
- package/dist/monitoring/system-monitor.service.d.ts +6 -5
- package/dist/options/enums.d.ts +22 -0
- package/dist/options/job-options.d.ts +2 -1
- package/dist/port-queue.d.ts +76 -4
- package/dist/{postgresql-driver-BUHuyRYj.js → postgresql-driver-CPHv5SUT.js} +128 -55
- package/dist/postgresql-driver-CPHv5SUT.js.map +1 -0
- package/dist/{postgresql-driver-CIk94XCq.cjs → postgresql-driver-DRT68TKb.cjs} +128 -55
- package/dist/postgresql-driver-DRT68TKb.cjs.map +1 -0
- package/dist/producer/producer.service.d.ts +12 -0
- package/dist/producer/results.d.ts +35 -1
- package/dist/{storage.constants-B5oQjxp5.cjs → storage.constants-BKeXcSQe.cjs} +13 -1
- package/dist/storage.constants-BKeXcSQe.cjs.map +1 -0
- package/dist/{storage.constants-DwSzjjMZ.js → storage.constants-DYEQUmc8.js} +14 -2
- package/dist/storage.constants-DYEQUmc8.js.map +1 -0
- package/package.json +1 -1
- package/dist/migration-CoTjpgBl.cjs.map +0 -1
- package/dist/migration-D73ANkYV.js.map +0 -1
- package/dist/postgresql-driver-BUHuyRYj.js.map +0 -1
- package/dist/postgresql-driver-CIk94XCq.cjs.map +0 -1
- package/dist/storage.constants-B5oQjxp5.cjs.map +0 -1
- package/dist/storage.constants-DwSzjjMZ.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as DatabaseEngine, c as capabilities, D as DriverCapability, b as DeduplicationReason, A as ACTIVE_STATUSES, J as JobStatus, F as FINISHED_STATUSES } from "../../storage.constants-
|
|
2
|
-
import { T as TableName, B as BaseDriver, t as toMigrationSteps, M as MissingPeerDependencyError, D as DriverConnectionError, a as MigrationColumn, b as DriverQueryError, J as JOB_COLUMNS, Q as QueueColumn, c as JobColumn, S as ScheduleColumn, d as SCHEDULE_INSERT_COLUMNS, I as InstanceColumn, r as retentionStatusBit, e as MS_PER_SECOND, U as UnsupportedCapabilityError } from "../../migration-
|
|
1
|
+
import { a as DatabaseEngine, c as capabilities, D as DriverCapability, b as DeduplicationReason, A as ACTIVE_STATUSES, J as JobStatus, F as FINISHED_STATUSES } from "../../storage.constants-DYEQUmc8.js";
|
|
2
|
+
import { T as TableName, B as BaseDriver, t as toMigrationSteps, M as MissingPeerDependencyError, D as DriverConnectionError, a as MigrationColumn, b as DriverQueryError, J as JOB_COLUMNS, Q as QueueColumn, c as JobColumn, S as ScheduleColumn, d as SCHEDULE_INSERT_COLUMNS, I as InstanceColumn, r as retentionStatusBit, e as MS_PER_SECOND, U as UnsupportedCapabilityError } from "../../migration-D0IRP2oq.js";
|
|
3
3
|
function createIfAbsent(ddl) {
|
|
4
4
|
return `BEGIN
|
|
5
5
|
EXECUTE IMMEDIATE '${ddl.replace(/'/g, "''")}';
|
|
@@ -312,16 +312,9 @@ class OracleDriver extends BaseDriver {
|
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
314
|
/**
|
|
315
|
-
* Apply one
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
* safe because every statement in the migration swallows its "already exists" code: a crash
|
|
319
|
-
* between the DDL and the version row leaves a schema the next run re-applies as a no-op and then
|
|
320
|
-
* records. The version insert is guarded on its own absence for the same reason.
|
|
321
|
-
*/
|
|
322
|
-
/**
|
|
323
|
-
* Apply one step, then record it — **not** in one transaction, and it cannot be: Oracle commits each DDL statement implicitly, so no transaction can span them. A `BEGIN`
|
|
324
|
-
* around them would be silently discarded at the first `CREATE TABLE`.
|
|
315
|
+
* Apply one step, then record it — **not** in one transaction, and it cannot be: Oracle commits
|
|
316
|
+
* each DDL statement implicitly, so no transaction can span them. A `BEGIN` around them would be
|
|
317
|
+
* silently discarded at the first `CREATE TABLE`.
|
|
325
318
|
*
|
|
326
319
|
* What holds instead: every statement in this engine's migrations is idempotent, so an
|
|
327
320
|
* interruption between the DDL and the version insert is repaired by re-running the step, and the
|
|
@@ -398,11 +391,6 @@ class OracleDriver extends BaseDriver {
|
|
|
398
391
|
return results;
|
|
399
392
|
});
|
|
400
393
|
}
|
|
401
|
-
/**
|
|
402
|
-
* Locate the existing jobs that dedup this batch, in one lookup per distinct queue and key kind
|
|
403
|
-
* rather than two per job. No unique index enforces either key — dedup lives in code so every
|
|
404
|
-
* engine behaves identically and a duplicate returns the existing job instead of raising.
|
|
405
|
-
*/
|
|
406
394
|
/**
|
|
407
395
|
* Serialize the dedup-lookup-then-insert pair against another producer's, per queue.
|
|
408
396
|
*
|
|
@@ -423,11 +411,19 @@ class OracleDriver extends BaseDriver {
|
|
|
423
411
|
)
|
|
424
412
|
].sort();
|
|
425
413
|
if (!names.length) return;
|
|
426
|
-
await
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
414
|
+
await this.overIdChunks(names, async (chunk) => {
|
|
415
|
+
const res = await run(
|
|
416
|
+
`SELECT ${QueueColumn.NAME} FROM ${this.t(TableName.QUEUE)} WHERE ${QueueColumn.NAME} IN (${this.phList(chunk.length)}) FOR UPDATE`,
|
|
417
|
+
chunk
|
|
418
|
+
);
|
|
419
|
+
return res.rows;
|
|
420
|
+
});
|
|
430
421
|
}
|
|
422
|
+
/**
|
|
423
|
+
* Locate the existing jobs that dedup this batch, in one lookup per distinct queue and key kind
|
|
424
|
+
* rather than two per job. No unique index enforces either key — dedup lives in code so every
|
|
425
|
+
* engine behaves identically and a duplicate returns the existing job instead of raising.
|
|
426
|
+
*/
|
|
431
427
|
async findDeduplicated(jobs, run) {
|
|
432
428
|
const out = /* @__PURE__ */ new Map();
|
|
433
429
|
const cols = `${JobColumn.ID}, ${JobColumn.STATUS}, ${JobColumn.START_AFTER}`;
|
|
@@ -443,11 +439,14 @@ class OracleDriver extends BaseDriver {
|
|
|
443
439
|
...new Set(queueJobs.flatMap((j) => j.idempotencyKey ? [j.idempotencyKey] : []))
|
|
444
440
|
];
|
|
445
441
|
if (idemKeys.length) {
|
|
446
|
-
const
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
442
|
+
const rows = await this.overIdChunks(idemKeys, async (chunk) => {
|
|
443
|
+
const res = await run(
|
|
444
|
+
`SELECT ${cols}, ${JobColumn.IDEMPOTENCY_KEY} FROM ${this.t(TableName.JOB)} WHERE ${JobColumn.QUEUE_NAME} = ${this.ph(0)} AND ${JobColumn.IDEMPOTENCY_KEY} IN (${this.phList(chunk.length, 1)})`,
|
|
445
|
+
[queueName, ...chunk]
|
|
446
|
+
);
|
|
447
|
+
return res.rows;
|
|
448
|
+
});
|
|
449
|
+
const found = new Map(rows.map((r) => [String(r[JobColumn.IDEMPOTENCY_KEY]), r]));
|
|
451
450
|
for (const job of queueJobs) {
|
|
452
451
|
if (job.idempotencyKey == null) continue;
|
|
453
452
|
const row = found.get(job.idempotencyKey);
|
|
@@ -460,11 +459,14 @@ class OracleDriver extends BaseDriver {
|
|
|
460
459
|
)
|
|
461
460
|
];
|
|
462
461
|
if (singletonKeys.length) {
|
|
463
|
-
const
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
462
|
+
const rows = await this.overIdChunks(singletonKeys, async (chunk) => {
|
|
463
|
+
const res = await run(
|
|
464
|
+
`SELECT ${cols}, ${JobColumn.SINGLETON_KEY} FROM ${this.t(TableName.JOB)} WHERE ${JobColumn.QUEUE_NAME} = ${this.ph(0)} AND ${JobColumn.SINGLETON_KEY} IN (${this.phList(chunk.length, 1)}) AND ${JobColumn.STATUS} IN (${this.phList(ACTIVE_STATUSES.length, 1 + chunk.length)})`,
|
|
465
|
+
[queueName, ...chunk, ...ACTIVE_STATUSES]
|
|
466
|
+
);
|
|
467
|
+
return res.rows;
|
|
468
|
+
});
|
|
469
|
+
const found = new Map(rows.map((r) => [String(r[JobColumn.SINGLETON_KEY]), r]));
|
|
468
470
|
for (const job of queueJobs) {
|
|
469
471
|
if (out.has(job) || job.singletonKey == null) continue;
|
|
470
472
|
const row = found.get(job.singletonKey);
|
|
@@ -760,6 +762,17 @@ class OracleDriver extends BaseDriver {
|
|
|
760
762
|
);
|
|
761
763
|
return res.rows[0] ? this.mapJob(res.rows[0]) : null;
|
|
762
764
|
}
|
|
765
|
+
async findJobRefs(options) {
|
|
766
|
+
if (!options.jobIds.length) return [];
|
|
767
|
+
return this.overIdChunks(options.jobIds, async (jobIds) => {
|
|
768
|
+
const res = await this.runMaybeTx(
|
|
769
|
+
`SELECT ${JobColumn.ID}, ${JobColumn.QUEUE_NAME} FROM ${this.t(TableName.JOB)} WHERE ${JobColumn.ID} IN (${this.phList(jobIds.length)})`,
|
|
770
|
+
jobIds,
|
|
771
|
+
options.tx
|
|
772
|
+
);
|
|
773
|
+
return res.rows.map((r) => this.mapJobRef(r));
|
|
774
|
+
});
|
|
775
|
+
}
|
|
763
776
|
/**
|
|
764
777
|
* WHERE clauses for a job filter, appending each value to `params`. Shared by `getJobs` and
|
|
765
778
|
* `countJobs` so a page and its total can never disagree about what they select. `search` is
|
|
@@ -868,6 +881,12 @@ class OracleDriver extends BaseDriver {
|
|
|
868
881
|
clauses.push(`${QueueColumn.PROCESSING_PAUSED} = ${this.ph(params.length)}`);
|
|
869
882
|
params.push(this.boolIn(options.processingPaused));
|
|
870
883
|
}
|
|
884
|
+
if (options.names !== void 0) {
|
|
885
|
+
clauses.push(
|
|
886
|
+
options.names.length ? `${QueueColumn.NAME} IN (${this.phList(options.names.length, params.length)})` : "1 = 0"
|
|
887
|
+
);
|
|
888
|
+
params.push(...options.names);
|
|
889
|
+
}
|
|
871
890
|
return clauses.length ? `WHERE ${clauses.join(" AND ")}` : "";
|
|
872
891
|
}
|
|
873
892
|
async listQueues(options = {}) {
|
|
@@ -1020,30 +1039,37 @@ class OracleDriver extends BaseDriver {
|
|
|
1020
1039
|
}
|
|
1021
1040
|
// --- Queue control ---
|
|
1022
1041
|
async setQueuePaused(options) {
|
|
1023
|
-
const
|
|
1024
|
-
const
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
sets
|
|
1031
|
-
params
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
);
|
|
1042
|
-
const
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1042
|
+
const { queueName, ...rest } = options;
|
|
1043
|
+
const [row] = await this.setQueuesPaused({ ...rest, queueNames: [queueName] });
|
|
1044
|
+
return row ?? null;
|
|
1045
|
+
}
|
|
1046
|
+
async setQueuesPaused(options) {
|
|
1047
|
+
if (!options.queueNames.length) return [];
|
|
1048
|
+
return this.overIdChunks(options.queueNames, async (queueNames) => {
|
|
1049
|
+
const sets = [];
|
|
1050
|
+
const params = [];
|
|
1051
|
+
if (options.processingPaused !== void 0) {
|
|
1052
|
+
sets.push(`${QueueColumn.PROCESSING_PAUSED} = ${this.ph(params.length)}`);
|
|
1053
|
+
params.push(this.boolIn(options.processingPaused));
|
|
1054
|
+
}
|
|
1055
|
+
if (options.acceptingPaused !== void 0) {
|
|
1056
|
+
sets.push(`${QueueColumn.ACCEPTING_PAUSED} = ${this.ph(params.length)}`);
|
|
1057
|
+
params.push(this.boolIn(options.acceptingPaused));
|
|
1058
|
+
}
|
|
1059
|
+
sets.push(`${QueueColumn.UPDATED_AT} = ${this.ph(params.length)}`);
|
|
1060
|
+
params.push(options.now);
|
|
1061
|
+
const namesPh = this.phList(queueNames.length, params.length);
|
|
1062
|
+
return this.inTx(options.tx, async (run) => {
|
|
1063
|
+
await run(
|
|
1064
|
+
`UPDATE ${this.t(TableName.QUEUE)} SET ${sets.join(", ")} WHERE ${QueueColumn.NAME} IN (${namesPh})`,
|
|
1065
|
+
[...params, ...queueNames]
|
|
1066
|
+
);
|
|
1067
|
+
const res = await run(
|
|
1068
|
+
`SELECT * FROM ${this.t(TableName.QUEUE)} WHERE ${QueueColumn.NAME} IN (${this.phList(queueNames.length)})`,
|
|
1069
|
+
queueNames
|
|
1070
|
+
);
|
|
1071
|
+
return res.rows.map((r) => this.mapQueue(r));
|
|
1072
|
+
});
|
|
1047
1073
|
});
|
|
1048
1074
|
}
|
|
1049
1075
|
async ensureQueue(options) {
|
|
@@ -1160,19 +1186,72 @@ class OracleDriver extends BaseDriver {
|
|
|
1160
1186
|
);
|
|
1161
1187
|
return res.rows[0] ? this.mapInstance(res.rows[0]) : null;
|
|
1162
1188
|
}
|
|
1189
|
+
async getInstancesByKeys(options) {
|
|
1190
|
+
if (!options.instanceKeys.length) return [];
|
|
1191
|
+
return this.overIdChunks(options.instanceKeys, async (instanceKeys) => {
|
|
1192
|
+
const res = await this.runMaybeTx(
|
|
1193
|
+
`SELECT * FROM ${this.t(TableName.INSTANCE)} WHERE ${InstanceColumn.INSTANCE_KEY} IN (${this.phList(instanceKeys.length)})`,
|
|
1194
|
+
instanceKeys,
|
|
1195
|
+
options.tx
|
|
1196
|
+
);
|
|
1197
|
+
return res.rows.map((r) => this.mapInstance(r));
|
|
1198
|
+
});
|
|
1199
|
+
}
|
|
1163
1200
|
async setInstancePaused(options) {
|
|
1164
|
-
await this.
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1201
|
+
await this.setInstancesPaused({
|
|
1202
|
+
instanceKeys: [options.instanceKey],
|
|
1203
|
+
processingPaused: options.processingPaused,
|
|
1204
|
+
now: options.now
|
|
1205
|
+
});
|
|
1206
|
+
}
|
|
1207
|
+
async setInstancesPaused(options) {
|
|
1208
|
+
if (!options.instanceKeys.length) return [];
|
|
1209
|
+
return this.overIdChunks(options.instanceKeys, async (instanceKeys) => {
|
|
1210
|
+
const sets = `${InstanceColumn.PROCESSING_PAUSED} = ${this.ph(0)}, ${InstanceColumn.UPDATED_AT} = ${this.ph(1)}`;
|
|
1211
|
+
const params = [this.boolIn(options.processingPaused), options.now, ...instanceKeys];
|
|
1212
|
+
return this.inTx(options.tx, async (run) => {
|
|
1213
|
+
await run(
|
|
1214
|
+
`UPDATE ${this.t(TableName.INSTANCE)} SET ${sets} WHERE ${InstanceColumn.INSTANCE_KEY} IN (${this.phList(instanceKeys.length, 2)})`,
|
|
1215
|
+
params
|
|
1216
|
+
);
|
|
1217
|
+
const res = await run(
|
|
1218
|
+
`SELECT ${InstanceColumn.INSTANCE_KEY} FROM ${this.t(TableName.INSTANCE)} WHERE ${InstanceColumn.INSTANCE_KEY} IN (${this.phList(instanceKeys.length)})`,
|
|
1219
|
+
instanceKeys
|
|
1220
|
+
);
|
|
1221
|
+
return res.rows.map((r) => this.mapInstanceKey(r));
|
|
1222
|
+
});
|
|
1223
|
+
});
|
|
1168
1224
|
}
|
|
1169
1225
|
async deleteInstance(options) {
|
|
1170
|
-
const
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1226
|
+
const removed = await this.deleteInstances({
|
|
1227
|
+
instanceKeys: [options.instanceKey],
|
|
1228
|
+
...options.tx ? { tx: options.tx } : {}
|
|
1229
|
+
});
|
|
1230
|
+
return removed.length > 0;
|
|
1231
|
+
}
|
|
1232
|
+
async deleteInstances(options) {
|
|
1233
|
+
if (!options.instanceKeys.length) return [];
|
|
1234
|
+
return this.overIdChunks(options.instanceKeys, async (instanceKeys) => {
|
|
1235
|
+
const params = [...instanceKeys];
|
|
1236
|
+
let guard = "";
|
|
1237
|
+
if (options.seenBefore !== void 0) {
|
|
1238
|
+
guard = ` AND ${InstanceColumn.LAST_SEEN_AT} < ${this.ph(params.length)}`;
|
|
1239
|
+
params.push(options.seenBefore);
|
|
1240
|
+
}
|
|
1241
|
+
return this.inTx(options.tx, async (run) => {
|
|
1242
|
+
const sel = await run(
|
|
1243
|
+
`SELECT ${InstanceColumn.INSTANCE_KEY} FROM ${this.t(TableName.INSTANCE)} WHERE ${InstanceColumn.INSTANCE_KEY} IN (${this.phList(instanceKeys.length)})${guard} FOR UPDATE`,
|
|
1244
|
+
params
|
|
1245
|
+
);
|
|
1246
|
+
const keys = sel.rows.map((r) => this.mapInstanceKey(r));
|
|
1247
|
+
if (!keys.length) return [];
|
|
1248
|
+
await run(
|
|
1249
|
+
`DELETE FROM ${this.t(TableName.INSTANCE)} WHERE ${InstanceColumn.INSTANCE_KEY} IN (${this.phList(keys.length)})`,
|
|
1250
|
+
keys
|
|
1251
|
+
);
|
|
1252
|
+
return keys;
|
|
1253
|
+
});
|
|
1254
|
+
});
|
|
1176
1255
|
}
|
|
1177
1256
|
// --- Retention ---
|
|
1178
1257
|
async deleteFinishedJobs(options) {
|