@dudousxd/nestjs-durable-store-drizzle 0.24.6 → 0.25.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/index.cjs +13 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +14 -6
- package/dist/index.js.map +1 -1
- package/dist/pg/index.cjs +20 -9
- package/dist/pg/index.cjs.map +1 -1
- package/dist/pg/index.js +21 -10
- package/dist/pg/index.js.map +1 -1
- package/package.json +3 -3
package/dist/pg/index.cjs
CHANGED
|
@@ -406,6 +406,9 @@ function durablePgManagedTables() {
|
|
|
406
406
|
__name(durablePgManagedTables, "durablePgManagedTables");
|
|
407
407
|
|
|
408
408
|
// src/pg/drizzle-pg-state-store.ts
|
|
409
|
+
var RETENTION_EXCLUDED = [
|
|
410
|
+
import_nestjs_durable_core.LIFECYCLE_REGISTRY_WORKFLOW
|
|
411
|
+
];
|
|
409
412
|
function anyOf(conditions) {
|
|
410
413
|
const present = conditions.filter((c) => c !== void 0);
|
|
411
414
|
return present.length ? (0, import_drizzle_orm4.or)(...present) : import_drizzle_orm4.sql`1 = 0`;
|
|
@@ -463,10 +466,10 @@ var DrizzlePgStateStore = class _DrizzlePgStateStore {
|
|
|
463
466
|
}
|
|
464
467
|
async tryAdmitSingleton(runId, tag, workflow, limit, retryWakeAt) {
|
|
465
468
|
return this.db.transaction(async (tx) => {
|
|
466
|
-
const where = (0, import_drizzle_orm4.and)((0, import_drizzle_orm4.eq)(durableWorkflowRuns.workflow, workflow), (0, import_drizzle_orm4.inArray)(durableWorkflowRuns.status, import_nestjs_durable_core.SINGLETON_ACTIVE_STATUSES), this.scope());
|
|
467
|
-
await tx.
|
|
468
|
-
|
|
469
|
-
}).where(where);
|
|
469
|
+
const where = (0, import_drizzle_orm4.and)((0, import_drizzle_orm4.eq)(durableWorkflowRuns.workflow, workflow), (0, import_drizzle_orm4.inArray)(durableWorkflowRuns.status, import_nestjs_durable_core.SINGLETON_ACTIVE_STATUSES), hasTag(tag), this.scope());
|
|
470
|
+
await tx.select({
|
|
471
|
+
id: durableWorkflowRuns.id
|
|
472
|
+
}).from(durableWorkflowRuns).where(where).orderBy((0, import_drizzle_orm4.asc)(durableWorkflowRuns.id)).for("update");
|
|
470
473
|
const rows = await tx.select().from(durableWorkflowRuns).where(where);
|
|
471
474
|
const runs = rows.map(fromRunRow);
|
|
472
475
|
const tags = (0, import_nestjs_durable_core.singletonAdmissionTags)(runs, runId, tag, workflow, limit);
|
|
@@ -552,28 +555,31 @@ var DrizzlePgStateStore = class _DrizzlePgStateStore {
|
|
|
552
555
|
if (policy.maxAge == null && policy.maxCount == null) return 0;
|
|
553
556
|
const scoped = this.runFilters({
|
|
554
557
|
...policy.scope ?? {},
|
|
555
|
-
statuses
|
|
558
|
+
statuses,
|
|
559
|
+
excludeWorkflows: RETENTION_EXCLUDED
|
|
556
560
|
});
|
|
557
561
|
return this.db.transaction(async (tx) => {
|
|
558
562
|
const ids = /* @__PURE__ */ new Set();
|
|
559
563
|
if (policy.maxAge != null) {
|
|
560
564
|
const cutoff = new Date(nowMs - (0, import_nestjs_durable_core.parseDuration)(policy.maxAge));
|
|
561
565
|
const rows = await tx.select({
|
|
562
|
-
id: durableWorkflowRuns.id
|
|
566
|
+
id: durableWorkflowRuns.id,
|
|
567
|
+
tags: durableWorkflowRuns.tags
|
|
563
568
|
}).from(durableWorkflowRuns).where((0, import_drizzle_orm4.and)(...scoped, (0, import_drizzle_orm4.lt)(durableWorkflowRuns.updatedAt, cutoff))).orderBy((0, import_drizzle_orm4.asc)(durableWorkflowRuns.updatedAt)).limit(limit).for("update", {
|
|
564
569
|
skipLocked: true
|
|
565
570
|
});
|
|
566
|
-
for (const r of rows) ids.add(r.id);
|
|
571
|
+
for (const r of rows) if (!(0, import_nestjs_durable_core.retentionKeeps)(r.tags)) ids.add(r.id);
|
|
567
572
|
}
|
|
568
573
|
if (policy.maxCount != null && ids.size < limit) {
|
|
569
574
|
const rows = await tx.select({
|
|
570
|
-
id: durableWorkflowRuns.id
|
|
575
|
+
id: durableWorkflowRuns.id,
|
|
576
|
+
tags: durableWorkflowRuns.tags
|
|
571
577
|
}).from(durableWorkflowRuns).where((0, import_drizzle_orm4.and)(...scoped)).orderBy((0, import_drizzle_orm4.desc)(durableWorkflowRuns.updatedAt), (0, import_drizzle_orm4.desc)(durableWorkflowRuns.id)).limit(limit).offset(policy.maxCount).for("update", {
|
|
572
578
|
skipLocked: true
|
|
573
579
|
});
|
|
574
580
|
for (const r of rows) {
|
|
575
581
|
if (ids.size >= limit) break;
|
|
576
|
-
ids.add(r.id);
|
|
582
|
+
if (!(0, import_nestjs_durable_core.retentionKeeps)(r.tags)) ids.add(r.id);
|
|
577
583
|
}
|
|
578
584
|
}
|
|
579
585
|
if (ids.size === 0) return 0;
|
|
@@ -751,6 +757,8 @@ var DrizzlePgStateStore = class _DrizzlePgStateStore {
|
|
|
751
757
|
this.scope(),
|
|
752
758
|
query.workflow ? (0, import_drizzle_orm4.eq)(durableWorkflowRuns.workflow, query.workflow) : void 0,
|
|
753
759
|
query.workflows ? query.workflows.length ? (0, import_drizzle_orm4.inArray)(durableWorkflowRuns.workflow, query.workflows) : import_drizzle_orm4.sql`1 = 0` : void 0,
|
|
760
|
+
query.excludeWorkflows?.length ? (0, import_drizzle_orm4.notInArray)(durableWorkflowRuns.workflow, query.excludeWorkflows) : void 0,
|
|
761
|
+
query.updatedAfter !== void 0 ? (0, import_drizzle_orm4.gte)(durableWorkflowRuns.updatedAt, new Date(query.updatedAfter)) : void 0,
|
|
754
762
|
// The tenant boundary. Also the engine's execution-timeout sweep path
|
|
755
763
|
// (`listRuns({ workflow, status, namespace })`) — unscoped, it would cancel another tenant's runs.
|
|
756
764
|
namespaceFilter(query.namespace),
|
|
@@ -1142,6 +1150,9 @@ async function reindexAttributes(db, runId, attributes) {
|
|
|
1142
1150
|
}
|
|
1143
1151
|
__name(reindexAttributes, "reindexAttributes");
|
|
1144
1152
|
async function deleteRunsCascade(db, runIds) {
|
|
1153
|
+
await db.select({
|
|
1154
|
+
id: durableWorkflowRuns.id
|
|
1155
|
+
}).from(durableWorkflowRuns).where((0, import_drizzle_orm4.inArray)(durableWorkflowRuns.id, runIds)).orderBy((0, import_drizzle_orm4.asc)(durableWorkflowRuns.id)).for("update");
|
|
1145
1156
|
await db.delete(durableStepCheckpoints).where((0, import_drizzle_orm4.inArray)(durableStepCheckpoints.runId, runIds));
|
|
1146
1157
|
await db.delete(durableSignalWaiters).where((0, import_drizzle_orm4.inArray)(durableSignalWaiters.runId, runIds));
|
|
1147
1158
|
await db.delete(durableRunAttributes).where((0, import_drizzle_orm4.inArray)(durableRunAttributes.runId, runIds));
|