@portqueue/core 1.0.3 → 1.1.1
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,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
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";
|
|
3
|
+
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
4
|
function v1(names) {
|
|
4
5
|
const t = names.name;
|
|
5
6
|
const idx = names.derived;
|
|
@@ -116,7 +117,8 @@ class MysqlDriver extends BaseDriver {
|
|
|
116
117
|
migrations = toMigrationSteps(MYSQL_MIGRATIONS);
|
|
117
118
|
pool = null;
|
|
118
119
|
/**
|
|
119
|
-
* Connections holding the advisory locks this driver has taken, keyed by
|
|
120
|
+
* Connections holding the advisory locks this driver has taken, keyed by the runner's key and
|
|
121
|
+
* carrying the server-side name it resolved to (see `tryAdvisoryLock`). `GET_LOCK` is
|
|
120
122
|
* scoped to the **session**, so the connection that took a lock is the only one that can release
|
|
121
123
|
* it — and going through the pool would release it on whichever connection came out next.
|
|
122
124
|
*/
|
|
@@ -153,7 +155,7 @@ class MysqlDriver extends BaseDriver {
|
|
|
153
155
|
}
|
|
154
156
|
}
|
|
155
157
|
async disconnect() {
|
|
156
|
-
for (const conn of this.lockConns.values()) conn.release();
|
|
158
|
+
for (const { conn } of this.lockConns.values()) conn.release();
|
|
157
159
|
this.lockConns.clear();
|
|
158
160
|
if (this.pool && !this.options.pool) await this.pool.end();
|
|
159
161
|
this.pool = null;
|
|
@@ -165,22 +167,32 @@ class MysqlDriver extends BaseDriver {
|
|
|
165
167
|
* fresh database all ran the full DDL at the same time, surviving only because `v1` is
|
|
166
168
|
* `IF NOT EXISTS`-guarded throughout.
|
|
167
169
|
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
170
|
+
* A `GET_LOCK` name is **server-wide**, wider than the database the tables live in. The runner's
|
|
171
|
+
* key already carries the schema when one is configured; without one the tables live in the
|
|
172
|
+
* connection's default database, so the name is prefixed with `DATABASE()` here — otherwise two
|
|
173
|
+
* databases on one server with the default prefix would share one migration lock. A name is kept
|
|
174
|
+
* readable (for `performance_schema`) when it fits MySQL's 64-character cap and hashed when it does
|
|
175
|
+
* not, because truncating would let two different keys collapse into one lock.
|
|
171
176
|
*/
|
|
172
177
|
async tryAdvisoryLock(options) {
|
|
173
178
|
if (!this.pool) return false;
|
|
174
179
|
if (this.lockConns.has(options.key)) return true;
|
|
175
180
|
const conn = await this.pool.getConnection();
|
|
176
181
|
try {
|
|
177
|
-
|
|
182
|
+
let scoped = options.key;
|
|
183
|
+
if (!this.context.tableNames.schema) {
|
|
184
|
+
const [dbRows] = await conn.query("SELECT DATABASE() AS db", []);
|
|
185
|
+
const db = dbRows[0]?.db;
|
|
186
|
+
if (db != null) scoped = `${String(db)}.${options.key}`;
|
|
187
|
+
}
|
|
188
|
+
const name = lockName(scoped);
|
|
189
|
+
const [rows] = await conn.query("SELECT GET_LOCK(?, 0) AS locked", [name]);
|
|
178
190
|
const locked = rows[0]?.locked;
|
|
179
191
|
if (Number(locked) !== 1) {
|
|
180
192
|
conn.release();
|
|
181
193
|
return false;
|
|
182
194
|
}
|
|
183
|
-
this.lockConns.set(options.key, conn);
|
|
195
|
+
this.lockConns.set(options.key, { conn, name });
|
|
184
196
|
return true;
|
|
185
197
|
} catch (err) {
|
|
186
198
|
conn.release();
|
|
@@ -188,11 +200,12 @@ class MysqlDriver extends BaseDriver {
|
|
|
188
200
|
}
|
|
189
201
|
}
|
|
190
202
|
async releaseAdvisoryLock(options) {
|
|
191
|
-
const
|
|
192
|
-
if (!
|
|
203
|
+
const held = this.lockConns.get(options.key);
|
|
204
|
+
if (!held) return;
|
|
193
205
|
this.lockConns.delete(options.key);
|
|
206
|
+
const { conn, name } = held;
|
|
194
207
|
try {
|
|
195
|
-
await conn.query("SELECT RELEASE_LOCK(?)", [
|
|
208
|
+
await conn.query("SELECT RELEASE_LOCK(?)", [name]);
|
|
196
209
|
} finally {
|
|
197
210
|
conn.release();
|
|
198
211
|
}
|
|
@@ -275,16 +288,9 @@ class MysqlDriver extends BaseDriver {
|
|
|
275
288
|
}
|
|
276
289
|
}
|
|
277
290
|
/**
|
|
278
|
-
* Apply one
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
* transaction. That is safe because every statement in the migration is `IF NOT EXISTS`: a crash
|
|
282
|
-
* between the DDL and the version row leaves a schema the next run re-applies as a no-op and then
|
|
283
|
-
* records. The version insert is `INSERT IGNORE` for the same reason.
|
|
284
|
-
*/
|
|
285
|
-
/**
|
|
286
|
-
* Apply one step, then record it — **not** in one transaction, and it cannot be: MySQL commits each DDL statement implicitly, so no transaction can span them. A `BEGIN`
|
|
287
|
-
* around them would be silently discarded at the first `CREATE TABLE`.
|
|
291
|
+
* Apply one step, then record it — **not** in one transaction, and it cannot be: MySQL commits
|
|
292
|
+
* each DDL statement implicitly, so no transaction can span them. A `BEGIN` around them would be
|
|
293
|
+
* silently discarded at the first `CREATE TABLE`.
|
|
288
294
|
*
|
|
289
295
|
* What holds instead: every statement in this engine's migrations is idempotent, so an
|
|
290
296
|
* interruption between the DDL and the version insert is repaired by re-running the step, and the
|
|
@@ -363,11 +369,6 @@ class MysqlDriver extends BaseDriver {
|
|
|
363
369
|
return results;
|
|
364
370
|
});
|
|
365
371
|
}
|
|
366
|
-
/**
|
|
367
|
-
* Locate the existing jobs that dedup this batch, in one lookup per distinct queue and key kind
|
|
368
|
-
* rather than two per job. No unique index enforces either key — dedup lives in code so every
|
|
369
|
-
* engine behaves identically and a duplicate returns the existing job instead of raising.
|
|
370
|
-
*/
|
|
371
372
|
/**
|
|
372
373
|
* Serialize the dedup-lookup-then-insert pair against another producer's, per queue.
|
|
373
374
|
*
|
|
@@ -388,11 +389,19 @@ class MysqlDriver extends BaseDriver {
|
|
|
388
389
|
)
|
|
389
390
|
].sort();
|
|
390
391
|
if (!names.length) return;
|
|
391
|
-
await
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
392
|
+
await this.overIdChunks(names, async (chunk) => {
|
|
393
|
+
const res = await run(
|
|
394
|
+
`SELECT ${QueueColumn.NAME} FROM ${this.t(TableName.QUEUE)} WHERE ${QueueColumn.NAME} IN (${this.phList(chunk.length)}) FOR UPDATE`,
|
|
395
|
+
chunk
|
|
396
|
+
);
|
|
397
|
+
return res.rows;
|
|
398
|
+
});
|
|
395
399
|
}
|
|
400
|
+
/**
|
|
401
|
+
* Locate the existing jobs that dedup this batch, in one lookup per distinct queue and key kind
|
|
402
|
+
* rather than two per job. No unique index enforces either key — dedup lives in code so every
|
|
403
|
+
* engine behaves identically and a duplicate returns the existing job instead of raising.
|
|
404
|
+
*/
|
|
396
405
|
async findDeduplicated(jobs, run) {
|
|
397
406
|
const out = /* @__PURE__ */ new Map();
|
|
398
407
|
const cols = `${JobColumn.ID}, ${JobColumn.STATUS}, ${JobColumn.START_AFTER}`;
|
|
@@ -408,11 +417,14 @@ class MysqlDriver extends BaseDriver {
|
|
|
408
417
|
...new Set(queueJobs.flatMap((j) => j.idempotencyKey ? [j.idempotencyKey] : []))
|
|
409
418
|
];
|
|
410
419
|
if (idemKeys.length) {
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
420
|
+
const rows = await this.overIdChunks(idemKeys, async (chunk) => {
|
|
421
|
+
const res = await run(
|
|
422
|
+
`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)})`,
|
|
423
|
+
[queueName, ...chunk]
|
|
424
|
+
);
|
|
425
|
+
return res.rows;
|
|
426
|
+
});
|
|
427
|
+
const found = new Map(rows.map((r) => [String(r[JobColumn.IDEMPOTENCY_KEY]), r]));
|
|
416
428
|
for (const job of queueJobs) {
|
|
417
429
|
if (job.idempotencyKey == null) continue;
|
|
418
430
|
const row = found.get(job.idempotencyKey);
|
|
@@ -425,11 +437,14 @@ class MysqlDriver extends BaseDriver {
|
|
|
425
437
|
)
|
|
426
438
|
];
|
|
427
439
|
if (singletonKeys.length) {
|
|
428
|
-
const
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
440
|
+
const rows = await this.overIdChunks(singletonKeys, async (chunk) => {
|
|
441
|
+
const res = await run(
|
|
442
|
+
`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)})`,
|
|
443
|
+
[queueName, ...chunk, ...ACTIVE_STATUSES]
|
|
444
|
+
);
|
|
445
|
+
return res.rows;
|
|
446
|
+
});
|
|
447
|
+
const found = new Map(rows.map((r) => [String(r[JobColumn.SINGLETON_KEY]), r]));
|
|
433
448
|
for (const job of queueJobs) {
|
|
434
449
|
if (out.has(job) || job.singletonKey == null) continue;
|
|
435
450
|
const row = found.get(job.singletonKey);
|
|
@@ -731,6 +746,17 @@ class MysqlDriver extends BaseDriver {
|
|
|
731
746
|
);
|
|
732
747
|
return res.rows[0] ? this.mapJob(res.rows[0]) : null;
|
|
733
748
|
}
|
|
749
|
+
async findJobRefs(options) {
|
|
750
|
+
if (!options.jobIds.length) return [];
|
|
751
|
+
return this.overIdChunks(options.jobIds, async (jobIds) => {
|
|
752
|
+
const res = await this.runMaybeTx(
|
|
753
|
+
`SELECT ${JobColumn.ID}, ${JobColumn.QUEUE_NAME} FROM ${this.t(TableName.JOB)} WHERE ${JobColumn.ID} IN (${this.phList(jobIds.length)})`,
|
|
754
|
+
jobIds,
|
|
755
|
+
options.tx
|
|
756
|
+
);
|
|
757
|
+
return res.rows.map((r) => this.mapJobRef(r));
|
|
758
|
+
});
|
|
759
|
+
}
|
|
734
760
|
/**
|
|
735
761
|
* WHERE clauses for a job filter, appending each value to `params`. Shared by `getJobs` and
|
|
736
762
|
* `countJobs` so a page and its total can never disagree about what they select. `search` is
|
|
@@ -839,6 +865,12 @@ class MysqlDriver extends BaseDriver {
|
|
|
839
865
|
clauses.push(`${QueueColumn.PROCESSING_PAUSED} = ${this.ph(params.length)}`);
|
|
840
866
|
params.push(this.boolIn(options.processingPaused));
|
|
841
867
|
}
|
|
868
|
+
if (options.names !== void 0) {
|
|
869
|
+
clauses.push(
|
|
870
|
+
options.names.length ? `${QueueColumn.NAME} IN (${this.phList(options.names.length, params.length)})` : "1 = 0"
|
|
871
|
+
);
|
|
872
|
+
params.push(...options.names);
|
|
873
|
+
}
|
|
842
874
|
return clauses.length ? `WHERE ${clauses.join(" AND ")}` : "";
|
|
843
875
|
}
|
|
844
876
|
async listQueues(options = {}) {
|
|
@@ -992,30 +1024,37 @@ class MysqlDriver extends BaseDriver {
|
|
|
992
1024
|
}
|
|
993
1025
|
// --- Queue control ---
|
|
994
1026
|
async setQueuePaused(options) {
|
|
995
|
-
const
|
|
996
|
-
const
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
sets
|
|
1003
|
-
params
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
);
|
|
1014
|
-
const
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1027
|
+
const { queueName, ...rest } = options;
|
|
1028
|
+
const [row] = await this.setQueuesPaused({ ...rest, queueNames: [queueName] });
|
|
1029
|
+
return row ?? null;
|
|
1030
|
+
}
|
|
1031
|
+
async setQueuesPaused(options) {
|
|
1032
|
+
if (!options.queueNames.length) return [];
|
|
1033
|
+
return this.overIdChunks(options.queueNames, async (queueNames) => {
|
|
1034
|
+
const sets = [];
|
|
1035
|
+
const params = [];
|
|
1036
|
+
if (options.processingPaused !== void 0) {
|
|
1037
|
+
sets.push(`${QueueColumn.PROCESSING_PAUSED} = ${this.ph(params.length)}`);
|
|
1038
|
+
params.push(this.boolIn(options.processingPaused));
|
|
1039
|
+
}
|
|
1040
|
+
if (options.acceptingPaused !== void 0) {
|
|
1041
|
+
sets.push(`${QueueColumn.ACCEPTING_PAUSED} = ${this.ph(params.length)}`);
|
|
1042
|
+
params.push(this.boolIn(options.acceptingPaused));
|
|
1043
|
+
}
|
|
1044
|
+
sets.push(`${QueueColumn.UPDATED_AT} = ${this.ph(params.length)}`);
|
|
1045
|
+
params.push(options.now);
|
|
1046
|
+
const namesPh = this.phList(queueNames.length, params.length);
|
|
1047
|
+
return this.inTx(options.tx, async (run) => {
|
|
1048
|
+
await run(
|
|
1049
|
+
`UPDATE ${this.t(TableName.QUEUE)} SET ${sets.join(", ")} WHERE ${QueueColumn.NAME} IN (${namesPh})`,
|
|
1050
|
+
[...params, ...queueNames]
|
|
1051
|
+
);
|
|
1052
|
+
const res = await run(
|
|
1053
|
+
`SELECT * FROM ${this.t(TableName.QUEUE)} WHERE ${QueueColumn.NAME} IN (${this.phList(queueNames.length)})`,
|
|
1054
|
+
queueNames
|
|
1055
|
+
);
|
|
1056
|
+
return res.rows.map((r) => this.mapQueue(r));
|
|
1057
|
+
});
|
|
1019
1058
|
});
|
|
1020
1059
|
}
|
|
1021
1060
|
async ensureQueue(options) {
|
|
@@ -1137,19 +1176,72 @@ class MysqlDriver extends BaseDriver {
|
|
|
1137
1176
|
);
|
|
1138
1177
|
return res.rows[0] ? this.mapInstance(res.rows[0]) : null;
|
|
1139
1178
|
}
|
|
1179
|
+
async getInstancesByKeys(options) {
|
|
1180
|
+
if (!options.instanceKeys.length) return [];
|
|
1181
|
+
return this.overIdChunks(options.instanceKeys, async (instanceKeys) => {
|
|
1182
|
+
const res = await this.runMaybeTx(
|
|
1183
|
+
`SELECT * FROM ${this.t(TableName.INSTANCE)} WHERE ${InstanceColumn.INSTANCE_KEY} IN (${this.phList(instanceKeys.length)})`,
|
|
1184
|
+
instanceKeys,
|
|
1185
|
+
options.tx
|
|
1186
|
+
);
|
|
1187
|
+
return res.rows.map((r) => this.mapInstance(r));
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1140
1190
|
async setInstancePaused(options) {
|
|
1141
|
-
await this.
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1191
|
+
await this.setInstancesPaused({
|
|
1192
|
+
instanceKeys: [options.instanceKey],
|
|
1193
|
+
processingPaused: options.processingPaused,
|
|
1194
|
+
now: options.now
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
async setInstancesPaused(options) {
|
|
1198
|
+
if (!options.instanceKeys.length) return [];
|
|
1199
|
+
return this.overIdChunks(options.instanceKeys, async (instanceKeys) => {
|
|
1200
|
+
const sets = `${InstanceColumn.PROCESSING_PAUSED} = ${this.ph(0)}, ${InstanceColumn.UPDATED_AT} = ${this.ph(1)}`;
|
|
1201
|
+
const params = [this.boolIn(options.processingPaused), options.now, ...instanceKeys];
|
|
1202
|
+
return this.inTx(options.tx, async (run) => {
|
|
1203
|
+
await run(
|
|
1204
|
+
`UPDATE ${this.t(TableName.INSTANCE)} SET ${sets} WHERE ${InstanceColumn.INSTANCE_KEY} IN (${this.phList(instanceKeys.length, 2)})`,
|
|
1205
|
+
params
|
|
1206
|
+
);
|
|
1207
|
+
const res = await run(
|
|
1208
|
+
`SELECT ${InstanceColumn.INSTANCE_KEY} FROM ${this.t(TableName.INSTANCE)} WHERE ${InstanceColumn.INSTANCE_KEY} IN (${this.phList(instanceKeys.length)})`,
|
|
1209
|
+
instanceKeys
|
|
1210
|
+
);
|
|
1211
|
+
return res.rows.map((r) => this.mapInstanceKey(r));
|
|
1212
|
+
});
|
|
1213
|
+
});
|
|
1145
1214
|
}
|
|
1146
1215
|
async deleteInstance(options) {
|
|
1147
|
-
const
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1216
|
+
const removed = await this.deleteInstances({
|
|
1217
|
+
instanceKeys: [options.instanceKey],
|
|
1218
|
+
...options.tx ? { tx: options.tx } : {}
|
|
1219
|
+
});
|
|
1220
|
+
return removed.length > 0;
|
|
1221
|
+
}
|
|
1222
|
+
async deleteInstances(options) {
|
|
1223
|
+
if (!options.instanceKeys.length) return [];
|
|
1224
|
+
return this.overIdChunks(options.instanceKeys, async (instanceKeys) => {
|
|
1225
|
+
const params = [...instanceKeys];
|
|
1226
|
+
let guard = "";
|
|
1227
|
+
if (options.seenBefore !== void 0) {
|
|
1228
|
+
guard = ` AND ${InstanceColumn.LAST_SEEN_AT} < ${this.ph(params.length)}`;
|
|
1229
|
+
params.push(options.seenBefore);
|
|
1230
|
+
}
|
|
1231
|
+
return this.inTx(options.tx, async (run) => {
|
|
1232
|
+
const sel = await run(
|
|
1233
|
+
`SELECT ${InstanceColumn.INSTANCE_KEY} FROM ${this.t(TableName.INSTANCE)} WHERE ${InstanceColumn.INSTANCE_KEY} IN (${this.phList(instanceKeys.length)})${guard} FOR UPDATE`,
|
|
1234
|
+
params
|
|
1235
|
+
);
|
|
1236
|
+
const keys = sel.rows.map((r) => this.mapInstanceKey(r));
|
|
1237
|
+
if (!keys.length) return [];
|
|
1238
|
+
await run(
|
|
1239
|
+
`DELETE FROM ${this.t(TableName.INSTANCE)} WHERE ${InstanceColumn.INSTANCE_KEY} IN (${this.phList(keys.length)})`,
|
|
1240
|
+
keys
|
|
1241
|
+
);
|
|
1242
|
+
return keys;
|
|
1243
|
+
});
|
|
1244
|
+
});
|
|
1153
1245
|
}
|
|
1154
1246
|
// --- Retention ---
|
|
1155
1247
|
async deleteFinishedJobs(options) {
|
|
@@ -1206,7 +1298,8 @@ class MysqlDriver extends BaseDriver {
|
|
|
1206
1298
|
}
|
|
1207
1299
|
}
|
|
1208
1300
|
function lockName(key) {
|
|
1209
|
-
|
|
1301
|
+
if (key.length <= MYSQL_LOCK_NAME_MAX) return key;
|
|
1302
|
+
return `pq:${createHash("sha1").update(key).digest("hex")}`;
|
|
1210
1303
|
}
|
|
1211
1304
|
const MYSQL_LOCK_NAME_MAX = 64;
|
|
1212
1305
|
export {
|