@portqueue/core 1.0.2 → 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, c as JobColumn, S as ScheduleColumn, d as SCHEDULE_INSERT_COLUMNS, Q as QueueColumn, 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, c as JobColumn, S as ScheduleColumn, d as SCHEDULE_INSERT_COLUMNS, Q as QueueColumn, I as InstanceColumn, r as retentionStatusBit, e as MS_PER_SECOND, U as UnsupportedCapabilityError } from "../../migration-D0IRP2oq.js";
|
|
3
3
|
function v1(names) {
|
|
4
4
|
const t = names.name;
|
|
5
5
|
const idx = names.derived;
|
|
@@ -345,11 +345,14 @@ class SqliteDriver extends BaseDriver {
|
|
|
345
345
|
...new Set(queueJobs.flatMap((j) => j.idempotencyKey ? [j.idempotencyKey] : []))
|
|
346
346
|
];
|
|
347
347
|
if (idemKeys.length) {
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
348
|
+
const rows = await this.overIdChunks(idemKeys, async (chunk) => {
|
|
349
|
+
const res = await run(
|
|
350
|
+
`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)})`,
|
|
351
|
+
[queueName, ...chunk]
|
|
352
|
+
);
|
|
353
|
+
return res.rows;
|
|
354
|
+
});
|
|
355
|
+
const found = new Map(rows.map((r) => [String(r[JobColumn.IDEMPOTENCY_KEY]), r]));
|
|
353
356
|
for (const job of queueJobs) {
|
|
354
357
|
if (job.idempotencyKey == null) continue;
|
|
355
358
|
const row = found.get(job.idempotencyKey);
|
|
@@ -362,11 +365,14 @@ class SqliteDriver extends BaseDriver {
|
|
|
362
365
|
)
|
|
363
366
|
];
|
|
364
367
|
if (singletonKeys.length) {
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
368
|
+
const rows = await this.overIdChunks(singletonKeys, async (chunk) => {
|
|
369
|
+
const res = await run(
|
|
370
|
+
`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)})`,
|
|
371
|
+
[queueName, ...chunk, ...ACTIVE_STATUSES]
|
|
372
|
+
);
|
|
373
|
+
return res.rows;
|
|
374
|
+
});
|
|
375
|
+
const found = new Map(rows.map((r) => [String(r[JobColumn.SINGLETON_KEY]), r]));
|
|
370
376
|
for (const job of queueJobs) {
|
|
371
377
|
if (out.has(job) || job.singletonKey == null) continue;
|
|
372
378
|
const row = found.get(job.singletonKey);
|
|
@@ -634,6 +640,17 @@ class SqliteDriver extends BaseDriver {
|
|
|
634
640
|
);
|
|
635
641
|
return res.rows[0] ? this.mapJob(res.rows[0]) : null;
|
|
636
642
|
}
|
|
643
|
+
async findJobRefs(options) {
|
|
644
|
+
if (!options.jobIds.length) return [];
|
|
645
|
+
return this.overIdChunks(options.jobIds, async (jobIds) => {
|
|
646
|
+
const res = await this.runMaybeTx(
|
|
647
|
+
`SELECT ${JobColumn.ID}, ${JobColumn.QUEUE_NAME} FROM ${this.t(TableName.JOB)} WHERE ${JobColumn.ID} IN (${this.phList(jobIds.length)})`,
|
|
648
|
+
jobIds,
|
|
649
|
+
options.tx
|
|
650
|
+
);
|
|
651
|
+
return res.rows.map((r) => this.mapJobRef(r));
|
|
652
|
+
});
|
|
653
|
+
}
|
|
637
654
|
/**
|
|
638
655
|
* WHERE clauses for a job filter, appending each value to `params`. Shared by `getJobs` and
|
|
639
656
|
* `countJobs` so a page and its total can never disagree about what they select. `search` is
|
|
@@ -742,6 +759,12 @@ class SqliteDriver extends BaseDriver {
|
|
|
742
759
|
clauses.push(`${QueueColumn.PROCESSING_PAUSED} = ${this.ph(params.length)}`);
|
|
743
760
|
params.push(this.boolIn(options.processingPaused));
|
|
744
761
|
}
|
|
762
|
+
if (options.names !== void 0) {
|
|
763
|
+
clauses.push(
|
|
764
|
+
options.names.length ? `${QueueColumn.NAME} IN (${this.phList(options.names.length, params.length)})` : "1 = 0"
|
|
765
|
+
);
|
|
766
|
+
params.push(...options.names);
|
|
767
|
+
}
|
|
745
768
|
return clauses.length ? `WHERE ${clauses.join(" AND ")}` : "";
|
|
746
769
|
}
|
|
747
770
|
async listQueues(options = {}) {
|
|
@@ -881,26 +904,33 @@ class SqliteDriver extends BaseDriver {
|
|
|
881
904
|
}
|
|
882
905
|
// --- Queue control ---
|
|
883
906
|
async setQueuePaused(options) {
|
|
884
|
-
const
|
|
885
|
-
const
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
sets
|
|
892
|
-
params
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
907
|
+
const { queueName, ...rest } = options;
|
|
908
|
+
const [row] = await this.setQueuesPaused({ ...rest, queueNames: [queueName] });
|
|
909
|
+
return row ?? null;
|
|
910
|
+
}
|
|
911
|
+
async setQueuesPaused(options) {
|
|
912
|
+
if (!options.queueNames.length) return [];
|
|
913
|
+
return this.overIdChunks(options.queueNames, async (queueNames) => {
|
|
914
|
+
const sets = [];
|
|
915
|
+
const params = [];
|
|
916
|
+
if (options.processingPaused !== void 0) {
|
|
917
|
+
sets.push(`${QueueColumn.PROCESSING_PAUSED} = ${this.ph(params.length)}`);
|
|
918
|
+
params.push(this.boolIn(options.processingPaused));
|
|
919
|
+
}
|
|
920
|
+
if (options.acceptingPaused !== void 0) {
|
|
921
|
+
sets.push(`${QueueColumn.ACCEPTING_PAUSED} = ${this.ph(params.length)}`);
|
|
922
|
+
params.push(this.boolIn(options.acceptingPaused));
|
|
923
|
+
}
|
|
924
|
+
sets.push(`${QueueColumn.UPDATED_AT} = ${this.ph(params.length)}`);
|
|
925
|
+
params.push(options.now);
|
|
926
|
+
const namesPh = this.phList(queueNames.length, params.length);
|
|
927
|
+
const res = await this.runMaybeTx(
|
|
928
|
+
`UPDATE ${this.t(TableName.QUEUE)} SET ${sets.join(", ")} WHERE ${QueueColumn.NAME} IN (${namesPh}) RETURNING *`,
|
|
929
|
+
[...params, ...queueNames],
|
|
930
|
+
options.tx
|
|
931
|
+
);
|
|
932
|
+
return res.rows.map((r) => this.mapQueue(r));
|
|
933
|
+
});
|
|
904
934
|
}
|
|
905
935
|
async ensureQueue(options) {
|
|
906
936
|
return this.inTx(options.tx, async (run) => {
|
|
@@ -1015,19 +1045,60 @@ class SqliteDriver extends BaseDriver {
|
|
|
1015
1045
|
);
|
|
1016
1046
|
return res.rows[0] ? this.mapInstance(res.rows[0]) : null;
|
|
1017
1047
|
}
|
|
1048
|
+
async getInstancesByKeys(options) {
|
|
1049
|
+
if (!options.instanceKeys.length) return [];
|
|
1050
|
+
return this.overIdChunks(options.instanceKeys, async (instanceKeys) => {
|
|
1051
|
+
const res = await this.runMaybeTx(
|
|
1052
|
+
`SELECT * FROM ${this.t(TableName.INSTANCE)} WHERE ${InstanceColumn.INSTANCE_KEY} IN (${this.phList(instanceKeys.length)})`,
|
|
1053
|
+
instanceKeys,
|
|
1054
|
+
options.tx
|
|
1055
|
+
);
|
|
1056
|
+
return res.rows.map((r) => this.mapInstance(r));
|
|
1057
|
+
});
|
|
1058
|
+
}
|
|
1018
1059
|
async setInstancePaused(options) {
|
|
1019
|
-
await this.
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1060
|
+
await this.setInstancesPaused({
|
|
1061
|
+
instanceKeys: [options.instanceKey],
|
|
1062
|
+
processingPaused: options.processingPaused,
|
|
1063
|
+
now: options.now
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
async setInstancesPaused(options) {
|
|
1067
|
+
if (!options.instanceKeys.length) return [];
|
|
1068
|
+
return this.overIdChunks(options.instanceKeys, async (instanceKeys) => {
|
|
1069
|
+
const sets = `${InstanceColumn.PROCESSING_PAUSED} = ${this.ph(0)}, ${InstanceColumn.UPDATED_AT} = ${this.ph(1)}`;
|
|
1070
|
+
const params = [this.boolIn(options.processingPaused), options.now, ...instanceKeys];
|
|
1071
|
+
const res = await this.runMaybeTx(
|
|
1072
|
+
`UPDATE ${this.t(TableName.INSTANCE)} SET ${sets} WHERE ${InstanceColumn.INSTANCE_KEY} IN (${this.phList(instanceKeys.length, 2)}) RETURNING ${InstanceColumn.INSTANCE_KEY}`,
|
|
1073
|
+
params,
|
|
1074
|
+
options.tx
|
|
1075
|
+
);
|
|
1076
|
+
return res.rows.map((r) => this.mapInstanceKey(r));
|
|
1077
|
+
});
|
|
1023
1078
|
}
|
|
1024
1079
|
async deleteInstance(options) {
|
|
1025
|
-
const
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1080
|
+
const removed = await this.deleteInstances({
|
|
1081
|
+
instanceKeys: [options.instanceKey],
|
|
1082
|
+
...options.tx ? { tx: options.tx } : {}
|
|
1083
|
+
});
|
|
1084
|
+
return removed.length > 0;
|
|
1085
|
+
}
|
|
1086
|
+
async deleteInstances(options) {
|
|
1087
|
+
if (!options.instanceKeys.length) return [];
|
|
1088
|
+
return this.overIdChunks(options.instanceKeys, async (instanceKeys) => {
|
|
1089
|
+
const params = [...instanceKeys];
|
|
1090
|
+
let guard = "";
|
|
1091
|
+
if (options.seenBefore !== void 0) {
|
|
1092
|
+
guard = ` AND ${InstanceColumn.LAST_SEEN_AT} < ${this.ph(params.length)}`;
|
|
1093
|
+
params.push(options.seenBefore);
|
|
1094
|
+
}
|
|
1095
|
+
const res = await this.runMaybeTx(
|
|
1096
|
+
`DELETE FROM ${this.t(TableName.INSTANCE)} WHERE ${InstanceColumn.INSTANCE_KEY} IN (${this.phList(instanceKeys.length)})${guard} RETURNING ${InstanceColumn.INSTANCE_KEY}`,
|
|
1097
|
+
params,
|
|
1098
|
+
options.tx
|
|
1099
|
+
);
|
|
1100
|
+
return res.rows.map((r) => this.mapInstanceKey(r));
|
|
1101
|
+
});
|
|
1031
1102
|
}
|
|
1032
1103
|
// --- Retention ---
|
|
1033
1104
|
async deleteFinishedJobs(options) {
|