@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
|
@@ -94,16 +94,9 @@ export declare class OracleDriver extends BaseDriver implements Driver {
|
|
|
94
94
|
*/
|
|
95
95
|
getSchemaVersion(): Promise<number | null>;
|
|
96
96
|
/**
|
|
97
|
-
* Apply one
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* safe because every statement in the migration swallows its "already exists" code: a crash
|
|
101
|
-
* between the DDL and the version row leaves a schema the next run re-applies as a no-op and then
|
|
102
|
-
* records. The version insert is guarded on its own absence for the same reason.
|
|
103
|
-
*/
|
|
104
|
-
/**
|
|
105
|
-
* 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`
|
|
106
|
-
* around them would be silently discarded at the first `CREATE TABLE`.
|
|
97
|
+
* Apply one step, then record it — **not** in one transaction, and it cannot be: Oracle commits
|
|
98
|
+
* each DDL statement implicitly, so no transaction can span them. A `BEGIN` around them would be
|
|
99
|
+
* silently discarded at the first `CREATE TABLE`.
|
|
107
100
|
*
|
|
108
101
|
* What holds instead: every statement in this engine's migrations is idempotent, so an
|
|
109
102
|
* interruption between the DDL and the version insert is repaired by re-running the step, and the
|
|
@@ -128,11 +121,6 @@ export declare class OracleDriver extends BaseDriver implements Driver {
|
|
|
128
121
|
jobs: NewJobRecord[];
|
|
129
122
|
tx?: TransactionHandle;
|
|
130
123
|
}): Promise<InsertedJobRow[]>;
|
|
131
|
-
/**
|
|
132
|
-
* Locate the existing jobs that dedup this batch, in one lookup per distinct queue and key kind
|
|
133
|
-
* rather than two per job. No unique index enforces either key — dedup lives in code so every
|
|
134
|
-
* engine behaves identically and a duplicate returns the existing job instead of raising.
|
|
135
|
-
*/
|
|
136
124
|
/**
|
|
137
125
|
* Serialize the dedup-lookup-then-insert pair against another producer's, per queue.
|
|
138
126
|
*
|
|
@@ -145,6 +133,11 @@ export declare class OracleDriver extends BaseDriver implements Driver {
|
|
|
145
133
|
* before.
|
|
146
134
|
*/
|
|
147
135
|
private lockQueuesForDedup;
|
|
136
|
+
/**
|
|
137
|
+
* Locate the existing jobs that dedup this batch, in one lookup per distinct queue and key kind
|
|
138
|
+
* rather than two per job. No unique index enforces either key — dedup lives in code so every
|
|
139
|
+
* engine behaves identically and a duplicate returns the existing job instead of raising.
|
|
140
|
+
*/
|
|
148
141
|
private findDeduplicated;
|
|
149
142
|
/** Shape a dedup hit the way `insertJob`'s caller reports it. */
|
|
150
143
|
private dedupResult;
|
|
@@ -244,6 +237,10 @@ export declare class OracleDriver extends BaseDriver implements Driver {
|
|
|
244
237
|
jobId: string;
|
|
245
238
|
tx?: TransactionHandle;
|
|
246
239
|
}): Promise<JobRecord | null>;
|
|
240
|
+
findJobRefs(options: {
|
|
241
|
+
jobIds: string[];
|
|
242
|
+
tx?: TransactionHandle;
|
|
243
|
+
}): Promise<JobRef[]>;
|
|
247
244
|
/**
|
|
248
245
|
* WHERE clauses for a job filter, appending each value to `params`. Shared by `getJobs` and
|
|
249
246
|
* `countJobs` so a page and its total can never disagree about what they select. `search` is
|
|
@@ -319,6 +316,13 @@ export declare class OracleDriver extends BaseDriver implements Driver {
|
|
|
319
316
|
now: number;
|
|
320
317
|
tx?: TransactionHandle;
|
|
321
318
|
}): Promise<QueueRow | null>;
|
|
319
|
+
setQueuesPaused(options: {
|
|
320
|
+
queueNames: string[];
|
|
321
|
+
processingPaused?: boolean;
|
|
322
|
+
acceptingPaused?: boolean;
|
|
323
|
+
now: number;
|
|
324
|
+
tx?: TransactionHandle;
|
|
325
|
+
}): Promise<QueueRow[]>;
|
|
322
326
|
ensureQueue(options: {
|
|
323
327
|
name: string;
|
|
324
328
|
options?: QueueOptions;
|
|
@@ -345,15 +349,30 @@ export declare class OracleDriver extends BaseDriver implements Driver {
|
|
|
345
349
|
getInstance(options: {
|
|
346
350
|
instanceKey: string;
|
|
347
351
|
}): Promise<InstanceRow | null>;
|
|
352
|
+
getInstancesByKeys(options: {
|
|
353
|
+
instanceKeys: string[];
|
|
354
|
+
tx?: TransactionHandle;
|
|
355
|
+
}): Promise<InstanceRow[]>;
|
|
348
356
|
setInstancePaused(options: {
|
|
349
357
|
instanceKey: string;
|
|
350
358
|
processingPaused: boolean;
|
|
351
359
|
now: number;
|
|
352
360
|
}): Promise<void>;
|
|
361
|
+
setInstancesPaused(options: {
|
|
362
|
+
instanceKeys: string[];
|
|
363
|
+
processingPaused: boolean;
|
|
364
|
+
now: number;
|
|
365
|
+
tx?: TransactionHandle;
|
|
366
|
+
}): Promise<string[]>;
|
|
353
367
|
deleteInstance(options: {
|
|
354
368
|
instanceKey: string;
|
|
355
369
|
tx?: TransactionHandle;
|
|
356
370
|
}): Promise<boolean>;
|
|
371
|
+
deleteInstances(options: {
|
|
372
|
+
instanceKeys: string[];
|
|
373
|
+
seenBefore?: number;
|
|
374
|
+
tx?: TransactionHandle;
|
|
375
|
+
}): Promise<string[]>;
|
|
357
376
|
deleteFinishedJobs(options: {
|
|
358
377
|
olderThan: number;
|
|
359
378
|
limit: number;
|
|
@@ -22,9 +22,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
mod
|
|
23
23
|
));
|
|
24
24
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
25
|
-
const storage_constants = require("../../storage.constants-
|
|
26
|
-
const migration = require("../../migration-
|
|
27
|
-
const postgresqlDriver = require("../../postgresql-driver-
|
|
25
|
+
const storage_constants = require("../../storage.constants-BKeXcSQe.cjs");
|
|
26
|
+
const migration = require("../../migration-Dx8eUthW.cjs");
|
|
27
|
+
const postgresqlDriver = require("../../postgresql-driver-DRT68TKb.cjs");
|
|
28
28
|
const PGLITE_MIGRATIONS = [{ version: 1, statements: postgresqlDriver.v1 }];
|
|
29
29
|
class PgliteDriver extends postgresqlDriver.PostgresqlDriver {
|
|
30
30
|
engine = storage_constants.DatabaseEngine.PGLITE;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as DatabaseEngine, c as capabilities, D as DriverCapability } from "../../storage.constants-
|
|
2
|
-
import { t as toMigrationSteps, M as MissingPeerDependencyError, D as DriverConnectionError, U as UnsupportedCapabilityError } from "../../migration-
|
|
3
|
-
import { v as v1, P as PostgresqlDriver } from "../../postgresql-driver-
|
|
1
|
+
import { a as DatabaseEngine, c as capabilities, D as DriverCapability } from "../../storage.constants-DYEQUmc8.js";
|
|
2
|
+
import { t as toMigrationSteps, M as MissingPeerDependencyError, D as DriverConnectionError, U as UnsupportedCapabilityError } from "../../migration-D0IRP2oq.js";
|
|
3
|
+
import { v as v1, P as PostgresqlDriver } from "../../postgresql-driver-CPHv5SUT.js";
|
|
4
4
|
const PGLITE_MIGRATIONS = [{ version: 1, statements: v1 }];
|
|
5
5
|
class PgliteDriver extends PostgresqlDriver {
|
|
6
6
|
engine = DatabaseEngine.PGLITE;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const postgresqlDriver = require("../../postgresql-driver-
|
|
3
|
+
const postgresqlDriver = require("../../postgresql-driver-DRT68TKb.cjs");
|
|
4
4
|
exports.PostgresqlDriver = postgresqlDriver.PostgresqlDriver;
|
|
5
5
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -99,11 +99,6 @@ export declare class PostgresqlDriver extends BaseDriver implements Driver {
|
|
|
99
99
|
jobs: NewJobRecord[];
|
|
100
100
|
tx?: TransactionHandle;
|
|
101
101
|
}): Promise<InsertedJobRow[]>;
|
|
102
|
-
/**
|
|
103
|
-
* Locate the existing jobs that dedup this batch, in one lookup per distinct queue and key kind
|
|
104
|
-
* rather than two per job. No unique index enforces either key — dedup lives in code so every
|
|
105
|
-
* engine behaves identically and a duplicate returns the existing job instead of raising.
|
|
106
|
-
*/
|
|
107
102
|
/**
|
|
108
103
|
* Serialize the dedup-lookup-then-insert pair against another producer's, per queue.
|
|
109
104
|
*
|
|
@@ -116,6 +111,11 @@ export declare class PostgresqlDriver extends BaseDriver implements Driver {
|
|
|
116
111
|
* before.
|
|
117
112
|
*/
|
|
118
113
|
private lockQueuesForDedup;
|
|
114
|
+
/**
|
|
115
|
+
* Locate the existing jobs that dedup this batch, in one lookup per distinct queue and key kind
|
|
116
|
+
* rather than two per job. No unique index enforces either key — dedup lives in code so every
|
|
117
|
+
* engine behaves identically and a duplicate returns the existing job instead of raising.
|
|
118
|
+
*/
|
|
119
119
|
private findDeduplicated;
|
|
120
120
|
/** Shape a dedup hit the way `insertJob`'s caller reports it. */
|
|
121
121
|
protected dedupResult(row: Row, reason: DeduplicationReason): InsertedJobRow;
|
|
@@ -215,6 +215,10 @@ export declare class PostgresqlDriver extends BaseDriver implements Driver {
|
|
|
215
215
|
jobId: string;
|
|
216
216
|
tx?: TransactionHandle;
|
|
217
217
|
}): Promise<JobRecord | null>;
|
|
218
|
+
findJobRefs(options: {
|
|
219
|
+
jobIds: string[];
|
|
220
|
+
tx?: TransactionHandle;
|
|
221
|
+
}): Promise<JobRef[]>;
|
|
218
222
|
/**
|
|
219
223
|
* WHERE clauses for a job filter, appending each value to `params`. Shared by `getJobs` and
|
|
220
224
|
* `countJobs` so a page and its total can never disagree about what they select. `search` is
|
|
@@ -294,6 +298,13 @@ export declare class PostgresqlDriver extends BaseDriver implements Driver {
|
|
|
294
298
|
now: number;
|
|
295
299
|
tx?: TransactionHandle;
|
|
296
300
|
}): Promise<QueueRow | null>;
|
|
301
|
+
setQueuesPaused(options: {
|
|
302
|
+
queueNames: string[];
|
|
303
|
+
processingPaused?: boolean;
|
|
304
|
+
acceptingPaused?: boolean;
|
|
305
|
+
now: number;
|
|
306
|
+
tx?: TransactionHandle;
|
|
307
|
+
}): Promise<QueueRow[]>;
|
|
297
308
|
ensureQueue(options: {
|
|
298
309
|
name: string;
|
|
299
310
|
options?: QueueOptions;
|
|
@@ -320,15 +331,30 @@ export declare class PostgresqlDriver extends BaseDriver implements Driver {
|
|
|
320
331
|
getInstance(options: {
|
|
321
332
|
instanceKey: string;
|
|
322
333
|
}): Promise<InstanceRow | null>;
|
|
334
|
+
getInstancesByKeys(options: {
|
|
335
|
+
instanceKeys: string[];
|
|
336
|
+
tx?: TransactionHandle;
|
|
337
|
+
}): Promise<InstanceRow[]>;
|
|
323
338
|
setInstancePaused(options: {
|
|
324
339
|
instanceKey: string;
|
|
325
340
|
processingPaused: boolean;
|
|
326
341
|
now: number;
|
|
327
342
|
}): Promise<void>;
|
|
343
|
+
setInstancesPaused(options: {
|
|
344
|
+
instanceKeys: string[];
|
|
345
|
+
processingPaused: boolean;
|
|
346
|
+
now: number;
|
|
347
|
+
tx?: TransactionHandle;
|
|
348
|
+
}): Promise<string[]>;
|
|
328
349
|
deleteInstance(options: {
|
|
329
350
|
instanceKey: string;
|
|
330
351
|
tx?: TransactionHandle;
|
|
331
352
|
}): Promise<boolean>;
|
|
353
|
+
deleteInstances(options: {
|
|
354
|
+
instanceKeys: string[];
|
|
355
|
+
seenBefore?: number;
|
|
356
|
+
tx?: TransactionHandle;
|
|
357
|
+
}): Promise<string[]>;
|
|
332
358
|
deleteFinishedJobs(options: {
|
|
333
359
|
olderThan: number;
|
|
334
360
|
limit: number;
|
|
@@ -340,8 +366,8 @@ export declare class PostgresqlDriver extends BaseDriver implements Driver {
|
|
|
340
366
|
*
|
|
341
367
|
* The per-status term is what makes `retention.statuses` real. A row with a NULL
|
|
342
368
|
* `retention_statuses` is eligible in every finished status (the default); a row that named a
|
|
343
|
-
* subset is eligible only in one of those,
|
|
344
|
-
*
|
|
369
|
+
* subset is eligible only in one of those, tested as a bit of the `retention_statuses` bitmask
|
|
370
|
+
* (see `shared/retention-statuses.ts`).
|
|
345
371
|
*/
|
|
346
372
|
private retentionWhere;
|
|
347
373
|
private channel;
|
|
@@ -180,6 +180,8 @@ export declare abstract class BaseDriver {
|
|
|
180
180
|
scheduleId: string;
|
|
181
181
|
queueName: string;
|
|
182
182
|
};
|
|
183
|
+
/** An instance's key, as the instance batch mutations return it. */
|
|
184
|
+
protected mapInstanceKey(row: Row): string;
|
|
183
185
|
/** The ordered values for one job row, matching {@link JOB_COLUMNS} exactly. */
|
|
184
186
|
protected jobInsertValues(job: NewJobRecord): {
|
|
185
187
|
id: string;
|
|
@@ -19,7 +19,9 @@ import { Clock } from '../../util/clock';
|
|
|
19
19
|
* a maximum would read as complete while a version was missing.
|
|
20
20
|
*
|
|
21
21
|
* **Concurrency.** Where the engine has a named lock (PostgreSQL' `pg_try_advisory_lock`, MySQL's
|
|
22
|
-
* `GET_LOCK`) one instance migrates and the rest wait for the version to land
|
|
22
|
+
* `GET_LOCK`) one instance migrates and the rest wait for the version to land — taking the lock over
|
|
23
|
+
* if it frees up while their schema is still behind, rather than waiting out the timeout. The key is
|
|
24
|
+
* scoped by schema and prefix (see `lockKey`), because the lock is wider than the tables. Where it does not
|
|
23
25
|
* (Oracle, SQLite, PGLite) every instance proceeds, which is safe only because each engine's DDL is
|
|
24
26
|
* written to be idempotent — `IF NOT EXISTS`, `MERGE`, PL/SQL-guarded `CREATE INDEX` — and because
|
|
25
27
|
* the confirmation above turns a half-applied step into an error rather than a silent skip. For a
|
|
@@ -39,10 +41,23 @@ export declare class MigrationRunner {
|
|
|
39
41
|
/** Force-apply (the programmatic `pq.migrate()` / CLI path). */
|
|
40
42
|
migrate(): Promise<void>;
|
|
41
43
|
private migrateAuto;
|
|
44
|
+
/** The steps above `current`, in ascending version order. */
|
|
45
|
+
private pendingFrom;
|
|
42
46
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
47
|
+
* The named lock this deployment's migration serializes on: `[<schema>.]<tablePrefix>migrate`.
|
|
48
|
+
*
|
|
49
|
+
* Scoped by schema as well as prefix because the lock is wider than the tables it guards — a
|
|
50
|
+
* PostgreSQL advisory lock is database-wide and a MySQL `GET_LOCK` server-wide — so two deployments
|
|
51
|
+
* in different schemas with the default prefix used to share one key, and the second waited on a
|
|
52
|
+
* migration that was never going to land in its own schema. (MySQL additionally scopes an
|
|
53
|
+
* unqualified key by the connection's database; see `MysqlDriver.tryAdvisoryLock`.)
|
|
54
|
+
*/
|
|
55
|
+
private lockKey;
|
|
56
|
+
/**
|
|
57
|
+
* Poll until another instance's migration lands, or until the lock it held frees up while this
|
|
58
|
+
* schema is still behind — in which case `tryTakeOver` has taken it and this instance migrates.
|
|
59
|
+
* Timed against the injected clock, like every other deadline in the codebase, so a test with a
|
|
60
|
+
* fake clock controls this wait rather than spending real seconds inside it.
|
|
46
61
|
*/
|
|
47
62
|
private waitForVersion;
|
|
48
63
|
}
|
|
@@ -31,9 +31,11 @@ export interface FlavourMigration {
|
|
|
31
31
|
/**
|
|
32
32
|
* Wrap a driver's authored {@link FlavourMigration} list into the runner's {@link MigrationStep}
|
|
33
33
|
* units — resolving object names against the live context, and nothing else. The driver's
|
|
34
|
-
* `applyMigration` runs the statements *and* records the version in one transaction
|
|
35
|
-
*
|
|
36
|
-
*
|
|
34
|
+
* `applyMigration` runs the statements *and* records the version — in one transaction where the
|
|
35
|
+
* engine has transactional DDL (PostgreSQL, PGLite, SQLite); on MySQL and Oracle DDL commits
|
|
36
|
+
* implicitly, so the statements run first and must be idempotent, and the `MigrationRunner` reads the
|
|
37
|
+
* version back before the next step. This is the only piece of the migration path shared across
|
|
38
|
+
* engines: the mechanism, never the SQL.
|
|
37
39
|
*/
|
|
38
40
|
export declare function toMigrationSteps(migrations: FlavourMigration[]): MigrationStep[];
|
|
39
41
|
/** The highest version among a migration set (the schema version a build ships). */
|
|
@@ -22,8 +22,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
mod
|
|
23
23
|
));
|
|
24
24
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
25
|
-
const storage_constants = require("../../storage.constants-
|
|
26
|
-
const migration = require("../../migration-
|
|
25
|
+
const storage_constants = require("../../storage.constants-BKeXcSQe.cjs");
|
|
26
|
+
const migration = require("../../migration-Dx8eUthW.cjs");
|
|
27
27
|
function v1(names) {
|
|
28
28
|
const t = names.name;
|
|
29
29
|
const idx = names.derived;
|
|
@@ -369,11 +369,14 @@ class SqliteDriver extends migration.BaseDriver {
|
|
|
369
369
|
...new Set(queueJobs.flatMap((j) => j.idempotencyKey ? [j.idempotencyKey] : []))
|
|
370
370
|
];
|
|
371
371
|
if (idemKeys.length) {
|
|
372
|
-
const
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
372
|
+
const rows = await this.overIdChunks(idemKeys, async (chunk) => {
|
|
373
|
+
const res = await run(
|
|
374
|
+
`SELECT ${cols}, ${migration.JobColumn.IDEMPOTENCY_KEY} FROM ${this.t(migration.TableName.JOB)} WHERE ${migration.JobColumn.QUEUE_NAME} = ${this.ph(0)} AND ${migration.JobColumn.IDEMPOTENCY_KEY} IN (${this.phList(chunk.length, 1)})`,
|
|
375
|
+
[queueName, ...chunk]
|
|
376
|
+
);
|
|
377
|
+
return res.rows;
|
|
378
|
+
});
|
|
379
|
+
const found = new Map(rows.map((r) => [String(r[migration.JobColumn.IDEMPOTENCY_KEY]), r]));
|
|
377
380
|
for (const job of queueJobs) {
|
|
378
381
|
if (job.idempotencyKey == null) continue;
|
|
379
382
|
const row = found.get(job.idempotencyKey);
|
|
@@ -386,11 +389,14 @@ class SqliteDriver extends migration.BaseDriver {
|
|
|
386
389
|
)
|
|
387
390
|
];
|
|
388
391
|
if (singletonKeys.length) {
|
|
389
|
-
const
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
392
|
+
const rows = await this.overIdChunks(singletonKeys, async (chunk) => {
|
|
393
|
+
const res = await run(
|
|
394
|
+
`SELECT ${cols}, ${migration.JobColumn.SINGLETON_KEY} FROM ${this.t(migration.TableName.JOB)} WHERE ${migration.JobColumn.QUEUE_NAME} = ${this.ph(0)} AND ${migration.JobColumn.SINGLETON_KEY} IN (${this.phList(chunk.length, 1)}) AND ${migration.JobColumn.STATUS} IN (${this.phList(storage_constants.ACTIVE_STATUSES.length, 1 + chunk.length)})`,
|
|
395
|
+
[queueName, ...chunk, ...storage_constants.ACTIVE_STATUSES]
|
|
396
|
+
);
|
|
397
|
+
return res.rows;
|
|
398
|
+
});
|
|
399
|
+
const found = new Map(rows.map((r) => [String(r[migration.JobColumn.SINGLETON_KEY]), r]));
|
|
394
400
|
for (const job of queueJobs) {
|
|
395
401
|
if (out.has(job) || job.singletonKey == null) continue;
|
|
396
402
|
const row = found.get(job.singletonKey);
|
|
@@ -658,6 +664,17 @@ class SqliteDriver extends migration.BaseDriver {
|
|
|
658
664
|
);
|
|
659
665
|
return res.rows[0] ? this.mapJob(res.rows[0]) : null;
|
|
660
666
|
}
|
|
667
|
+
async findJobRefs(options) {
|
|
668
|
+
if (!options.jobIds.length) return [];
|
|
669
|
+
return this.overIdChunks(options.jobIds, async (jobIds) => {
|
|
670
|
+
const res = await this.runMaybeTx(
|
|
671
|
+
`SELECT ${migration.JobColumn.ID}, ${migration.JobColumn.QUEUE_NAME} FROM ${this.t(migration.TableName.JOB)} WHERE ${migration.JobColumn.ID} IN (${this.phList(jobIds.length)})`,
|
|
672
|
+
jobIds,
|
|
673
|
+
options.tx
|
|
674
|
+
);
|
|
675
|
+
return res.rows.map((r) => this.mapJobRef(r));
|
|
676
|
+
});
|
|
677
|
+
}
|
|
661
678
|
/**
|
|
662
679
|
* WHERE clauses for a job filter, appending each value to `params`. Shared by `getJobs` and
|
|
663
680
|
* `countJobs` so a page and its total can never disagree about what they select. `search` is
|
|
@@ -766,6 +783,12 @@ class SqliteDriver extends migration.BaseDriver {
|
|
|
766
783
|
clauses.push(`${migration.QueueColumn.PROCESSING_PAUSED} = ${this.ph(params.length)}`);
|
|
767
784
|
params.push(this.boolIn(options.processingPaused));
|
|
768
785
|
}
|
|
786
|
+
if (options.names !== void 0) {
|
|
787
|
+
clauses.push(
|
|
788
|
+
options.names.length ? `${migration.QueueColumn.NAME} IN (${this.phList(options.names.length, params.length)})` : "1 = 0"
|
|
789
|
+
);
|
|
790
|
+
params.push(...options.names);
|
|
791
|
+
}
|
|
769
792
|
return clauses.length ? `WHERE ${clauses.join(" AND ")}` : "";
|
|
770
793
|
}
|
|
771
794
|
async listQueues(options = {}) {
|
|
@@ -905,26 +928,33 @@ class SqliteDriver extends migration.BaseDriver {
|
|
|
905
928
|
}
|
|
906
929
|
// --- Queue control ---
|
|
907
930
|
async setQueuePaused(options) {
|
|
908
|
-
const
|
|
909
|
-
const
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
sets
|
|
916
|
-
params
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
931
|
+
const { queueName, ...rest } = options;
|
|
932
|
+
const [row] = await this.setQueuesPaused({ ...rest, queueNames: [queueName] });
|
|
933
|
+
return row ?? null;
|
|
934
|
+
}
|
|
935
|
+
async setQueuesPaused(options) {
|
|
936
|
+
if (!options.queueNames.length) return [];
|
|
937
|
+
return this.overIdChunks(options.queueNames, async (queueNames) => {
|
|
938
|
+
const sets = [];
|
|
939
|
+
const params = [];
|
|
940
|
+
if (options.processingPaused !== void 0) {
|
|
941
|
+
sets.push(`${migration.QueueColumn.PROCESSING_PAUSED} = ${this.ph(params.length)}`);
|
|
942
|
+
params.push(this.boolIn(options.processingPaused));
|
|
943
|
+
}
|
|
944
|
+
if (options.acceptingPaused !== void 0) {
|
|
945
|
+
sets.push(`${migration.QueueColumn.ACCEPTING_PAUSED} = ${this.ph(params.length)}`);
|
|
946
|
+
params.push(this.boolIn(options.acceptingPaused));
|
|
947
|
+
}
|
|
948
|
+
sets.push(`${migration.QueueColumn.UPDATED_AT} = ${this.ph(params.length)}`);
|
|
949
|
+
params.push(options.now);
|
|
950
|
+
const namesPh = this.phList(queueNames.length, params.length);
|
|
951
|
+
const res = await this.runMaybeTx(
|
|
952
|
+
`UPDATE ${this.t(migration.TableName.QUEUE)} SET ${sets.join(", ")} WHERE ${migration.QueueColumn.NAME} IN (${namesPh}) RETURNING *`,
|
|
953
|
+
[...params, ...queueNames],
|
|
954
|
+
options.tx
|
|
955
|
+
);
|
|
956
|
+
return res.rows.map((r) => this.mapQueue(r));
|
|
957
|
+
});
|
|
928
958
|
}
|
|
929
959
|
async ensureQueue(options) {
|
|
930
960
|
return this.inTx(options.tx, async (run) => {
|
|
@@ -1039,19 +1069,60 @@ class SqliteDriver extends migration.BaseDriver {
|
|
|
1039
1069
|
);
|
|
1040
1070
|
return res.rows[0] ? this.mapInstance(res.rows[0]) : null;
|
|
1041
1071
|
}
|
|
1072
|
+
async getInstancesByKeys(options) {
|
|
1073
|
+
if (!options.instanceKeys.length) return [];
|
|
1074
|
+
return this.overIdChunks(options.instanceKeys, async (instanceKeys) => {
|
|
1075
|
+
const res = await this.runMaybeTx(
|
|
1076
|
+
`SELECT * FROM ${this.t(migration.TableName.INSTANCE)} WHERE ${migration.InstanceColumn.INSTANCE_KEY} IN (${this.phList(instanceKeys.length)})`,
|
|
1077
|
+
instanceKeys,
|
|
1078
|
+
options.tx
|
|
1079
|
+
);
|
|
1080
|
+
return res.rows.map((r) => this.mapInstance(r));
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1042
1083
|
async setInstancePaused(options) {
|
|
1043
|
-
await this.
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1084
|
+
await this.setInstancesPaused({
|
|
1085
|
+
instanceKeys: [options.instanceKey],
|
|
1086
|
+
processingPaused: options.processingPaused,
|
|
1087
|
+
now: options.now
|
|
1088
|
+
});
|
|
1089
|
+
}
|
|
1090
|
+
async setInstancesPaused(options) {
|
|
1091
|
+
if (!options.instanceKeys.length) return [];
|
|
1092
|
+
return this.overIdChunks(options.instanceKeys, async (instanceKeys) => {
|
|
1093
|
+
const sets = `${migration.InstanceColumn.PROCESSING_PAUSED} = ${this.ph(0)}, ${migration.InstanceColumn.UPDATED_AT} = ${this.ph(1)}`;
|
|
1094
|
+
const params = [this.boolIn(options.processingPaused), options.now, ...instanceKeys];
|
|
1095
|
+
const res = await this.runMaybeTx(
|
|
1096
|
+
`UPDATE ${this.t(migration.TableName.INSTANCE)} SET ${sets} WHERE ${migration.InstanceColumn.INSTANCE_KEY} IN (${this.phList(instanceKeys.length, 2)}) RETURNING ${migration.InstanceColumn.INSTANCE_KEY}`,
|
|
1097
|
+
params,
|
|
1098
|
+
options.tx
|
|
1099
|
+
);
|
|
1100
|
+
return res.rows.map((r) => this.mapInstanceKey(r));
|
|
1101
|
+
});
|
|
1047
1102
|
}
|
|
1048
1103
|
async deleteInstance(options) {
|
|
1049
|
-
const
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1104
|
+
const removed = await this.deleteInstances({
|
|
1105
|
+
instanceKeys: [options.instanceKey],
|
|
1106
|
+
...options.tx ? { tx: options.tx } : {}
|
|
1107
|
+
});
|
|
1108
|
+
return removed.length > 0;
|
|
1109
|
+
}
|
|
1110
|
+
async deleteInstances(options) {
|
|
1111
|
+
if (!options.instanceKeys.length) return [];
|
|
1112
|
+
return this.overIdChunks(options.instanceKeys, async (instanceKeys) => {
|
|
1113
|
+
const params = [...instanceKeys];
|
|
1114
|
+
let guard = "";
|
|
1115
|
+
if (options.seenBefore !== void 0) {
|
|
1116
|
+
guard = ` AND ${migration.InstanceColumn.LAST_SEEN_AT} < ${this.ph(params.length)}`;
|
|
1117
|
+
params.push(options.seenBefore);
|
|
1118
|
+
}
|
|
1119
|
+
const res = await this.runMaybeTx(
|
|
1120
|
+
`DELETE FROM ${this.t(migration.TableName.INSTANCE)} WHERE ${migration.InstanceColumn.INSTANCE_KEY} IN (${this.phList(instanceKeys.length)})${guard} RETURNING ${migration.InstanceColumn.INSTANCE_KEY}`,
|
|
1121
|
+
params,
|
|
1122
|
+
options.tx
|
|
1123
|
+
);
|
|
1124
|
+
return res.rows.map((r) => this.mapInstanceKey(r));
|
|
1125
|
+
});
|
|
1055
1126
|
}
|
|
1056
1127
|
// --- Retention ---
|
|
1057
1128
|
async deleteFinishedJobs(options) {
|