@dudousxd/nestjs-durable-store-drizzle 0.24.5 → 0.24.7
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/pg/index.cjs +16 -4
- package/dist/pg/index.cjs.map +1 -1
- package/dist/pg/index.js +16 -4
- package/dist/pg/index.js.map +1 -1
- package/package.json +3 -3
package/dist/pg/index.js
CHANGED
|
@@ -423,10 +423,10 @@ var DrizzlePgStateStore = class _DrizzlePgStateStore {
|
|
|
423
423
|
}
|
|
424
424
|
async tryAdmitSingleton(runId, tag, workflow, limit, retryWakeAt) {
|
|
425
425
|
return this.db.transaction(async (tx) => {
|
|
426
|
-
const where = and(eq(durableWorkflowRuns.workflow, workflow), inArray(durableWorkflowRuns.status, SINGLETON_ACTIVE_STATUSES), this.scope());
|
|
427
|
-
await tx.
|
|
428
|
-
|
|
429
|
-
}).where(where);
|
|
426
|
+
const where = and(eq(durableWorkflowRuns.workflow, workflow), inArray(durableWorkflowRuns.status, SINGLETON_ACTIVE_STATUSES), hasTag(tag), this.scope());
|
|
427
|
+
await tx.select({
|
|
428
|
+
id: durableWorkflowRuns.id
|
|
429
|
+
}).from(durableWorkflowRuns).where(where).orderBy(asc(durableWorkflowRuns.id)).for("update");
|
|
430
430
|
const rows = await tx.select().from(durableWorkflowRuns).where(where);
|
|
431
431
|
const runs = rows.map(fromRunRow);
|
|
432
432
|
const tags = singletonAdmissionTags(runs, runId, tag, workflow, limit);
|
|
@@ -442,6 +442,11 @@ var DrizzlePgStateStore = class _DrizzlePgStateStore {
|
|
|
442
442
|
});
|
|
443
443
|
}
|
|
444
444
|
async createRun(run) {
|
|
445
|
+
if (normalizeAttributeRows(run.id, run.searchAttributes).length === 0) {
|
|
446
|
+
await this.db.insert(durableWorkflowRuns).values(toRunRow(run));
|
|
447
|
+
await this.db.delete(durableRunAttributes).where(eq(durableRunAttributes.runId, run.id));
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
445
450
|
await this.db.transaction(async (tx) => {
|
|
446
451
|
await tx.insert(durableWorkflowRuns).values(toRunRow(run));
|
|
447
452
|
await reindexAttributes(tx, run.id, run.searchAttributes);
|
|
@@ -452,6 +457,10 @@ var DrizzlePgStateStore = class _DrizzlePgStateStore {
|
|
|
452
457
|
const row = toRunPatch(patch);
|
|
453
458
|
const reindex = "searchAttributes" in patch;
|
|
454
459
|
if (!Object.keys(row).length && !reindex) return;
|
|
460
|
+
if (!reindex) {
|
|
461
|
+
await this.db.update(durableWorkflowRuns).set(row).where(eq(durableWorkflowRuns.id, runId));
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
455
464
|
await this.db.transaction(async (tx) => {
|
|
456
465
|
if (Object.keys(row).length) await tx.update(durableWorkflowRuns).set(row).where(eq(durableWorkflowRuns.id, runId));
|
|
457
466
|
if (reindex) await reindexAttributes(tx, runId, patch.searchAttributes);
|
|
@@ -1093,6 +1102,9 @@ async function reindexAttributes(db, runId, attributes) {
|
|
|
1093
1102
|
}
|
|
1094
1103
|
__name(reindexAttributes, "reindexAttributes");
|
|
1095
1104
|
async function deleteRunsCascade(db, runIds) {
|
|
1105
|
+
await db.select({
|
|
1106
|
+
id: durableWorkflowRuns.id
|
|
1107
|
+
}).from(durableWorkflowRuns).where(inArray(durableWorkflowRuns.id, runIds)).orderBy(asc(durableWorkflowRuns.id)).for("update");
|
|
1096
1108
|
await db.delete(durableStepCheckpoints).where(inArray(durableStepCheckpoints.runId, runIds));
|
|
1097
1109
|
await db.delete(durableSignalWaiters).where(inArray(durableSignalWaiters.runId, runIds));
|
|
1098
1110
|
await db.delete(durableRunAttributes).where(inArray(durableRunAttributes.runId, runIds));
|