@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
|
@@ -22,8 +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
|
|
26
|
-
const
|
|
25
|
+
const node_crypto = require("node:crypto");
|
|
26
|
+
const storage_constants = require("../../storage.constants-BKeXcSQe.cjs");
|
|
27
|
+
const migration = require("../../migration-Dx8eUthW.cjs");
|
|
27
28
|
function v1(names) {
|
|
28
29
|
const t = names.name;
|
|
29
30
|
const idx = names.derived;
|
|
@@ -140,7 +141,8 @@ class MysqlDriver extends migration.BaseDriver {
|
|
|
140
141
|
migrations = migration.toMigrationSteps(MYSQL_MIGRATIONS);
|
|
141
142
|
pool = null;
|
|
142
143
|
/**
|
|
143
|
-
* Connections holding the advisory locks this driver has taken, keyed by
|
|
144
|
+
* Connections holding the advisory locks this driver has taken, keyed by the runner's key and
|
|
145
|
+
* carrying the server-side name it resolved to (see `tryAdvisoryLock`). `GET_LOCK` is
|
|
144
146
|
* scoped to the **session**, so the connection that took a lock is the only one that can release
|
|
145
147
|
* it — and going through the pool would release it on whichever connection came out next.
|
|
146
148
|
*/
|
|
@@ -177,7 +179,7 @@ class MysqlDriver extends migration.BaseDriver {
|
|
|
177
179
|
}
|
|
178
180
|
}
|
|
179
181
|
async disconnect() {
|
|
180
|
-
for (const conn of this.lockConns.values()) conn.release();
|
|
182
|
+
for (const { conn } of this.lockConns.values()) conn.release();
|
|
181
183
|
this.lockConns.clear();
|
|
182
184
|
if (this.pool && !this.options.pool) await this.pool.end();
|
|
183
185
|
this.pool = null;
|
|
@@ -189,22 +191,32 @@ class MysqlDriver extends migration.BaseDriver {
|
|
|
189
191
|
* fresh database all ran the full DDL at the same time, surviving only because `v1` is
|
|
190
192
|
* `IF NOT EXISTS`-guarded throughout.
|
|
191
193
|
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
194
|
+
* A `GET_LOCK` name is **server-wide**, wider than the database the tables live in. The runner's
|
|
195
|
+
* key already carries the schema when one is configured; without one the tables live in the
|
|
196
|
+
* connection's default database, so the name is prefixed with `DATABASE()` here — otherwise two
|
|
197
|
+
* databases on one server with the default prefix would share one migration lock. A name is kept
|
|
198
|
+
* readable (for `performance_schema`) when it fits MySQL's 64-character cap and hashed when it does
|
|
199
|
+
* not, because truncating would let two different keys collapse into one lock.
|
|
195
200
|
*/
|
|
196
201
|
async tryAdvisoryLock(options) {
|
|
197
202
|
if (!this.pool) return false;
|
|
198
203
|
if (this.lockConns.has(options.key)) return true;
|
|
199
204
|
const conn = await this.pool.getConnection();
|
|
200
205
|
try {
|
|
201
|
-
|
|
206
|
+
let scoped = options.key;
|
|
207
|
+
if (!this.context.tableNames.schema) {
|
|
208
|
+
const [dbRows] = await conn.query("SELECT DATABASE() AS db", []);
|
|
209
|
+
const db = dbRows[0]?.db;
|
|
210
|
+
if (db != null) scoped = `${String(db)}.${options.key}`;
|
|
211
|
+
}
|
|
212
|
+
const name = lockName(scoped);
|
|
213
|
+
const [rows] = await conn.query("SELECT GET_LOCK(?, 0) AS locked", [name]);
|
|
202
214
|
const locked = rows[0]?.locked;
|
|
203
215
|
if (Number(locked) !== 1) {
|
|
204
216
|
conn.release();
|
|
205
217
|
return false;
|
|
206
218
|
}
|
|
207
|
-
this.lockConns.set(options.key, conn);
|
|
219
|
+
this.lockConns.set(options.key, { conn, name });
|
|
208
220
|
return true;
|
|
209
221
|
} catch (err) {
|
|
210
222
|
conn.release();
|
|
@@ -212,11 +224,12 @@ class MysqlDriver extends migration.BaseDriver {
|
|
|
212
224
|
}
|
|
213
225
|
}
|
|
214
226
|
async releaseAdvisoryLock(options) {
|
|
215
|
-
const
|
|
216
|
-
if (!
|
|
227
|
+
const held = this.lockConns.get(options.key);
|
|
228
|
+
if (!held) return;
|
|
217
229
|
this.lockConns.delete(options.key);
|
|
230
|
+
const { conn, name } = held;
|
|
218
231
|
try {
|
|
219
|
-
await conn.query("SELECT RELEASE_LOCK(?)", [
|
|
232
|
+
await conn.query("SELECT RELEASE_LOCK(?)", [name]);
|
|
220
233
|
} finally {
|
|
221
234
|
conn.release();
|
|
222
235
|
}
|
|
@@ -299,16 +312,9 @@ class MysqlDriver extends migration.BaseDriver {
|
|
|
299
312
|
}
|
|
300
313
|
}
|
|
301
314
|
/**
|
|
302
|
-
* Apply one
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
* transaction. That is safe because every statement in the migration is `IF NOT EXISTS`: a crash
|
|
306
|
-
* between the DDL and the version row leaves a schema the next run re-applies as a no-op and then
|
|
307
|
-
* records. The version insert is `INSERT IGNORE` for the same reason.
|
|
308
|
-
*/
|
|
309
|
-
/**
|
|
310
|
-
* 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`
|
|
311
|
-
* 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: MySQL 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`.
|
|
312
318
|
*
|
|
313
319
|
* What holds instead: every statement in this engine's migrations is idempotent, so an
|
|
314
320
|
* interruption between the DDL and the version insert is repaired by re-running the step, and the
|
|
@@ -387,11 +393,6 @@ class MysqlDriver extends migration.BaseDriver {
|
|
|
387
393
|
return results;
|
|
388
394
|
});
|
|
389
395
|
}
|
|
390
|
-
/**
|
|
391
|
-
* Locate the existing jobs that dedup this batch, in one lookup per distinct queue and key kind
|
|
392
|
-
* rather than two per job. No unique index enforces either key — dedup lives in code so every
|
|
393
|
-
* engine behaves identically and a duplicate returns the existing job instead of raising.
|
|
394
|
-
*/
|
|
395
396
|
/**
|
|
396
397
|
* Serialize the dedup-lookup-then-insert pair against another producer's, per queue.
|
|
397
398
|
*
|
|
@@ -412,11 +413,19 @@ class MysqlDriver extends migration.BaseDriver {
|
|
|
412
413
|
)
|
|
413
414
|
].sort();
|
|
414
415
|
if (!names.length) return;
|
|
415
|
-
await
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
416
|
+
await this.overIdChunks(names, async (chunk) => {
|
|
417
|
+
const res = await run(
|
|
418
|
+
`SELECT ${migration.QueueColumn.NAME} FROM ${this.t(migration.TableName.QUEUE)} WHERE ${migration.QueueColumn.NAME} IN (${this.phList(chunk.length)}) FOR UPDATE`,
|
|
419
|
+
chunk
|
|
420
|
+
);
|
|
421
|
+
return res.rows;
|
|
422
|
+
});
|
|
419
423
|
}
|
|
424
|
+
/**
|
|
425
|
+
* Locate the existing jobs that dedup this batch, in one lookup per distinct queue and key kind
|
|
426
|
+
* rather than two per job. No unique index enforces either key — dedup lives in code so every
|
|
427
|
+
* engine behaves identically and a duplicate returns the existing job instead of raising.
|
|
428
|
+
*/
|
|
420
429
|
async findDeduplicated(jobs, run) {
|
|
421
430
|
const out = /* @__PURE__ */ new Map();
|
|
422
431
|
const cols = `${migration.JobColumn.ID}, ${migration.JobColumn.STATUS}, ${migration.JobColumn.START_AFTER}`;
|
|
@@ -432,11 +441,14 @@ class MysqlDriver extends migration.BaseDriver {
|
|
|
432
441
|
...new Set(queueJobs.flatMap((j) => j.idempotencyKey ? [j.idempotencyKey] : []))
|
|
433
442
|
];
|
|
434
443
|
if (idemKeys.length) {
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
444
|
+
const rows = await this.overIdChunks(idemKeys, async (chunk) => {
|
|
445
|
+
const res = await run(
|
|
446
|
+
`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)})`,
|
|
447
|
+
[queueName, ...chunk]
|
|
448
|
+
);
|
|
449
|
+
return res.rows;
|
|
450
|
+
});
|
|
451
|
+
const found = new Map(rows.map((r) => [String(r[migration.JobColumn.IDEMPOTENCY_KEY]), r]));
|
|
440
452
|
for (const job of queueJobs) {
|
|
441
453
|
if (job.idempotencyKey == null) continue;
|
|
442
454
|
const row = found.get(job.idempotencyKey);
|
|
@@ -449,11 +461,14 @@ class MysqlDriver extends migration.BaseDriver {
|
|
|
449
461
|
)
|
|
450
462
|
];
|
|
451
463
|
if (singletonKeys.length) {
|
|
452
|
-
const
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
464
|
+
const rows = await this.overIdChunks(singletonKeys, async (chunk) => {
|
|
465
|
+
const res = await run(
|
|
466
|
+
`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)})`,
|
|
467
|
+
[queueName, ...chunk, ...storage_constants.ACTIVE_STATUSES]
|
|
468
|
+
);
|
|
469
|
+
return res.rows;
|
|
470
|
+
});
|
|
471
|
+
const found = new Map(rows.map((r) => [String(r[migration.JobColumn.SINGLETON_KEY]), r]));
|
|
457
472
|
for (const job of queueJobs) {
|
|
458
473
|
if (out.has(job) || job.singletonKey == null) continue;
|
|
459
474
|
const row = found.get(job.singletonKey);
|
|
@@ -755,6 +770,17 @@ class MysqlDriver extends migration.BaseDriver {
|
|
|
755
770
|
);
|
|
756
771
|
return res.rows[0] ? this.mapJob(res.rows[0]) : null;
|
|
757
772
|
}
|
|
773
|
+
async findJobRefs(options) {
|
|
774
|
+
if (!options.jobIds.length) return [];
|
|
775
|
+
return this.overIdChunks(options.jobIds, async (jobIds) => {
|
|
776
|
+
const res = await this.runMaybeTx(
|
|
777
|
+
`SELECT ${migration.JobColumn.ID}, ${migration.JobColumn.QUEUE_NAME} FROM ${this.t(migration.TableName.JOB)} WHERE ${migration.JobColumn.ID} IN (${this.phList(jobIds.length)})`,
|
|
778
|
+
jobIds,
|
|
779
|
+
options.tx
|
|
780
|
+
);
|
|
781
|
+
return res.rows.map((r) => this.mapJobRef(r));
|
|
782
|
+
});
|
|
783
|
+
}
|
|
758
784
|
/**
|
|
759
785
|
* WHERE clauses for a job filter, appending each value to `params`. Shared by `getJobs` and
|
|
760
786
|
* `countJobs` so a page and its total can never disagree about what they select. `search` is
|
|
@@ -863,6 +889,12 @@ class MysqlDriver extends migration.BaseDriver {
|
|
|
863
889
|
clauses.push(`${migration.QueueColumn.PROCESSING_PAUSED} = ${this.ph(params.length)}`);
|
|
864
890
|
params.push(this.boolIn(options.processingPaused));
|
|
865
891
|
}
|
|
892
|
+
if (options.names !== void 0) {
|
|
893
|
+
clauses.push(
|
|
894
|
+
options.names.length ? `${migration.QueueColumn.NAME} IN (${this.phList(options.names.length, params.length)})` : "1 = 0"
|
|
895
|
+
);
|
|
896
|
+
params.push(...options.names);
|
|
897
|
+
}
|
|
866
898
|
return clauses.length ? `WHERE ${clauses.join(" AND ")}` : "";
|
|
867
899
|
}
|
|
868
900
|
async listQueues(options = {}) {
|
|
@@ -1016,30 +1048,37 @@ class MysqlDriver extends migration.BaseDriver {
|
|
|
1016
1048
|
}
|
|
1017
1049
|
// --- Queue control ---
|
|
1018
1050
|
async setQueuePaused(options) {
|
|
1019
|
-
const
|
|
1020
|
-
const
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
sets
|
|
1027
|
-
params
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
);
|
|
1038
|
-
const
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1051
|
+
const { queueName, ...rest } = options;
|
|
1052
|
+
const [row] = await this.setQueuesPaused({ ...rest, queueNames: [queueName] });
|
|
1053
|
+
return row ?? null;
|
|
1054
|
+
}
|
|
1055
|
+
async setQueuesPaused(options) {
|
|
1056
|
+
if (!options.queueNames.length) return [];
|
|
1057
|
+
return this.overIdChunks(options.queueNames, async (queueNames) => {
|
|
1058
|
+
const sets = [];
|
|
1059
|
+
const params = [];
|
|
1060
|
+
if (options.processingPaused !== void 0) {
|
|
1061
|
+
sets.push(`${migration.QueueColumn.PROCESSING_PAUSED} = ${this.ph(params.length)}`);
|
|
1062
|
+
params.push(this.boolIn(options.processingPaused));
|
|
1063
|
+
}
|
|
1064
|
+
if (options.acceptingPaused !== void 0) {
|
|
1065
|
+
sets.push(`${migration.QueueColumn.ACCEPTING_PAUSED} = ${this.ph(params.length)}`);
|
|
1066
|
+
params.push(this.boolIn(options.acceptingPaused));
|
|
1067
|
+
}
|
|
1068
|
+
sets.push(`${migration.QueueColumn.UPDATED_AT} = ${this.ph(params.length)}`);
|
|
1069
|
+
params.push(options.now);
|
|
1070
|
+
const namesPh = this.phList(queueNames.length, params.length);
|
|
1071
|
+
return this.inTx(options.tx, async (run) => {
|
|
1072
|
+
await run(
|
|
1073
|
+
`UPDATE ${this.t(migration.TableName.QUEUE)} SET ${sets.join(", ")} WHERE ${migration.QueueColumn.NAME} IN (${namesPh})`,
|
|
1074
|
+
[...params, ...queueNames]
|
|
1075
|
+
);
|
|
1076
|
+
const res = await run(
|
|
1077
|
+
`SELECT * FROM ${this.t(migration.TableName.QUEUE)} WHERE ${migration.QueueColumn.NAME} IN (${this.phList(queueNames.length)})`,
|
|
1078
|
+
queueNames
|
|
1079
|
+
);
|
|
1080
|
+
return res.rows.map((r) => this.mapQueue(r));
|
|
1081
|
+
});
|
|
1043
1082
|
});
|
|
1044
1083
|
}
|
|
1045
1084
|
async ensureQueue(options) {
|
|
@@ -1161,19 +1200,72 @@ class MysqlDriver extends migration.BaseDriver {
|
|
|
1161
1200
|
);
|
|
1162
1201
|
return res.rows[0] ? this.mapInstance(res.rows[0]) : null;
|
|
1163
1202
|
}
|
|
1203
|
+
async getInstancesByKeys(options) {
|
|
1204
|
+
if (!options.instanceKeys.length) return [];
|
|
1205
|
+
return this.overIdChunks(options.instanceKeys, async (instanceKeys) => {
|
|
1206
|
+
const res = await this.runMaybeTx(
|
|
1207
|
+
`SELECT * FROM ${this.t(migration.TableName.INSTANCE)} WHERE ${migration.InstanceColumn.INSTANCE_KEY} IN (${this.phList(instanceKeys.length)})`,
|
|
1208
|
+
instanceKeys,
|
|
1209
|
+
options.tx
|
|
1210
|
+
);
|
|
1211
|
+
return res.rows.map((r) => this.mapInstance(r));
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1164
1214
|
async setInstancePaused(options) {
|
|
1165
|
-
await this.
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1215
|
+
await this.setInstancesPaused({
|
|
1216
|
+
instanceKeys: [options.instanceKey],
|
|
1217
|
+
processingPaused: options.processingPaused,
|
|
1218
|
+
now: options.now
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1221
|
+
async setInstancesPaused(options) {
|
|
1222
|
+
if (!options.instanceKeys.length) return [];
|
|
1223
|
+
return this.overIdChunks(options.instanceKeys, async (instanceKeys) => {
|
|
1224
|
+
const sets = `${migration.InstanceColumn.PROCESSING_PAUSED} = ${this.ph(0)}, ${migration.InstanceColumn.UPDATED_AT} = ${this.ph(1)}`;
|
|
1225
|
+
const params = [this.boolIn(options.processingPaused), options.now, ...instanceKeys];
|
|
1226
|
+
return this.inTx(options.tx, async (run) => {
|
|
1227
|
+
await run(
|
|
1228
|
+
`UPDATE ${this.t(migration.TableName.INSTANCE)} SET ${sets} WHERE ${migration.InstanceColumn.INSTANCE_KEY} IN (${this.phList(instanceKeys.length, 2)})`,
|
|
1229
|
+
params
|
|
1230
|
+
);
|
|
1231
|
+
const res = await run(
|
|
1232
|
+
`SELECT ${migration.InstanceColumn.INSTANCE_KEY} FROM ${this.t(migration.TableName.INSTANCE)} WHERE ${migration.InstanceColumn.INSTANCE_KEY} IN (${this.phList(instanceKeys.length)})`,
|
|
1233
|
+
instanceKeys
|
|
1234
|
+
);
|
|
1235
|
+
return res.rows.map((r) => this.mapInstanceKey(r));
|
|
1236
|
+
});
|
|
1237
|
+
});
|
|
1169
1238
|
}
|
|
1170
1239
|
async deleteInstance(options) {
|
|
1171
|
-
const
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1240
|
+
const removed = await this.deleteInstances({
|
|
1241
|
+
instanceKeys: [options.instanceKey],
|
|
1242
|
+
...options.tx ? { tx: options.tx } : {}
|
|
1243
|
+
});
|
|
1244
|
+
return removed.length > 0;
|
|
1245
|
+
}
|
|
1246
|
+
async deleteInstances(options) {
|
|
1247
|
+
if (!options.instanceKeys.length) return [];
|
|
1248
|
+
return this.overIdChunks(options.instanceKeys, async (instanceKeys) => {
|
|
1249
|
+
const params = [...instanceKeys];
|
|
1250
|
+
let guard = "";
|
|
1251
|
+
if (options.seenBefore !== void 0) {
|
|
1252
|
+
guard = ` AND ${migration.InstanceColumn.LAST_SEEN_AT} < ${this.ph(params.length)}`;
|
|
1253
|
+
params.push(options.seenBefore);
|
|
1254
|
+
}
|
|
1255
|
+
return this.inTx(options.tx, async (run) => {
|
|
1256
|
+
const sel = await run(
|
|
1257
|
+
`SELECT ${migration.InstanceColumn.INSTANCE_KEY} FROM ${this.t(migration.TableName.INSTANCE)} WHERE ${migration.InstanceColumn.INSTANCE_KEY} IN (${this.phList(instanceKeys.length)})${guard} FOR UPDATE`,
|
|
1258
|
+
params
|
|
1259
|
+
);
|
|
1260
|
+
const keys = sel.rows.map((r) => this.mapInstanceKey(r));
|
|
1261
|
+
if (!keys.length) return [];
|
|
1262
|
+
await run(
|
|
1263
|
+
`DELETE FROM ${this.t(migration.TableName.INSTANCE)} WHERE ${migration.InstanceColumn.INSTANCE_KEY} IN (${this.phList(keys.length)})`,
|
|
1264
|
+
keys
|
|
1265
|
+
);
|
|
1266
|
+
return keys;
|
|
1267
|
+
});
|
|
1268
|
+
});
|
|
1177
1269
|
}
|
|
1178
1270
|
// --- Retention ---
|
|
1179
1271
|
async deleteFinishedJobs(options) {
|
|
@@ -1230,7 +1322,8 @@ class MysqlDriver extends migration.BaseDriver {
|
|
|
1230
1322
|
}
|
|
1231
1323
|
}
|
|
1232
1324
|
function lockName(key) {
|
|
1233
|
-
|
|
1325
|
+
if (key.length <= MYSQL_LOCK_NAME_MAX) return key;
|
|
1326
|
+
return `pq:${node_crypto.createHash("sha1").update(key).digest("hex")}`;
|
|
1234
1327
|
}
|
|
1235
1328
|
const MYSQL_LOCK_NAME_MAX = 64;
|
|
1236
1329
|
exports.MysqlDriver = MysqlDriver;
|