@dudousxd/nestjs-durable-store-typeorm 0.22.0 → 0.23.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 +68 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +68 -19
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1019,31 +1019,24 @@ var TypeOrmStateStore = class {
|
|
|
1019
1019
|
}
|
|
1020
1020
|
async updateRun(runId, inputPatch) {
|
|
1021
1021
|
const patch = inputPatch.status && import_nestjs_durable_core.TERMINAL_RUN_STATUSES.includes(inputPatch.status) ? await (0, import_nestjs_durable_core.clearTerminalSingletonAdmission)(runId, inputPatch, (id) => this.getRun(id)) : inputPatch;
|
|
1022
|
-
const update =
|
|
1023
|
-
if ("workflow" in patch) update.workflow = patch.workflow;
|
|
1024
|
-
if ("workflowVersion" in patch) update.workflowVersion = patch.workflowVersion;
|
|
1025
|
-
if ("status" in patch) update.status = patch.status;
|
|
1026
|
-
if ("input" in patch) update.input = patch.input ?? null;
|
|
1027
|
-
if ("output" in patch) update.output = patch.output ?? null;
|
|
1028
|
-
if ("error" in patch) update.error = patch.error ?? null;
|
|
1029
|
-
if ("wakeAt" in patch) update.wakeAt = patch.wakeAt == null ? null : new Date(patch.wakeAt);
|
|
1030
|
-
if ("lockedBy" in patch) update.lockedBy = patch.lockedBy ?? null;
|
|
1031
|
-
if ("lockedUntil" in patch) update.lockedUntil = patch.lockedUntil == null ? null : new Date(patch.lockedUntil);
|
|
1032
|
-
if ("awaitingDecisionTaskId" in patch) update.awaitingDecisionTaskId = patch.awaitingDecisionTaskId ?? null;
|
|
1033
|
-
if ("recoveryAttempts" in patch) update.recoveryAttempts = patch.recoveryAttempts;
|
|
1034
|
-
if ("tags" in patch) update.tags = patch.tags ?? null;
|
|
1035
|
-
if ("searchAttributes" in patch) update.searchAttributes = patch.searchAttributes ?? null;
|
|
1036
|
-
if ("priority" in patch) update.priority = patch.priority ?? null;
|
|
1037
|
-
if ("namespace" in patch) update.namespace = patch.namespace ?? "default";
|
|
1038
|
-
if ("origin" in patch) update.origin = patch.origin ?? null;
|
|
1039
|
-
if ("createdAt" in patch) update.createdAt = patch.createdAt;
|
|
1040
|
-
if ("updatedAt" in patch) update.updatedAt = patch.updatedAt;
|
|
1022
|
+
const update = runUpdateSet(patch);
|
|
1041
1023
|
const result = await this.runs().createQueryBuilder().update().set(update).where({
|
|
1042
1024
|
id: runId
|
|
1043
1025
|
}).execute();
|
|
1044
1026
|
if (!result.affected) throw new Error(`run ${runId} not found`);
|
|
1045
1027
|
if ("searchAttributes" in patch) await this.reindexAttributes(runId, patch.searchAttributes);
|
|
1046
1028
|
}
|
|
1029
|
+
async updateRunIf(runId, expectedStatuses, inputPatch) {
|
|
1030
|
+
if (expectedStatuses.length === 0) return false;
|
|
1031
|
+
const patch = inputPatch.status && import_nestjs_durable_core.TERMINAL_RUN_STATUSES.includes(inputPatch.status) ? await (0, import_nestjs_durable_core.clearTerminalSingletonAdmission)(runId, inputPatch, (id) => this.getRun(id)) : inputPatch;
|
|
1032
|
+
const result = await this.runs().createQueryBuilder().update().set(runUpdateSet(patch)).where({
|
|
1033
|
+
id: runId,
|
|
1034
|
+
status: (0, import_typeorm2.In)(expectedStatuses)
|
|
1035
|
+
}).execute();
|
|
1036
|
+
if (!result.affected) return false;
|
|
1037
|
+
if ("searchAttributes" in patch) await this.reindexAttributes(runId, patch.searchAttributes);
|
|
1038
|
+
return true;
|
|
1039
|
+
}
|
|
1047
1040
|
async getRun(runId) {
|
|
1048
1041
|
const e = await this.runs().findOneBy({
|
|
1049
1042
|
id: runId
|
|
@@ -1163,6 +1156,39 @@ var TypeOrmStateStore = class {
|
|
|
1163
1156
|
});
|
|
1164
1157
|
return rows.map(fromRunEntity);
|
|
1165
1158
|
}
|
|
1159
|
+
async listOrphanedRuns(nowMs, limit, namespace) {
|
|
1160
|
+
if (limit <= 0) return [];
|
|
1161
|
+
const now = new Date(nowMs);
|
|
1162
|
+
const rows = await this.runs().find({
|
|
1163
|
+
where: [
|
|
1164
|
+
{
|
|
1165
|
+
status: (0, import_typeorm2.In)([
|
|
1166
|
+
"running",
|
|
1167
|
+
"cancelling"
|
|
1168
|
+
]),
|
|
1169
|
+
lockedUntil: (0, import_typeorm2.IsNull)(),
|
|
1170
|
+
...namespace !== void 0 ? {
|
|
1171
|
+
namespace
|
|
1172
|
+
} : {}
|
|
1173
|
+
},
|
|
1174
|
+
{
|
|
1175
|
+
status: (0, import_typeorm2.In)([
|
|
1176
|
+
"running",
|
|
1177
|
+
"cancelling"
|
|
1178
|
+
]),
|
|
1179
|
+
lockedUntil: (0, import_typeorm2.LessThanOrEqual)(now),
|
|
1180
|
+
...namespace !== void 0 ? {
|
|
1181
|
+
namespace
|
|
1182
|
+
} : {}
|
|
1183
|
+
}
|
|
1184
|
+
],
|
|
1185
|
+
order: {
|
|
1186
|
+
createdAt: "ASC"
|
|
1187
|
+
},
|
|
1188
|
+
take: limit
|
|
1189
|
+
});
|
|
1190
|
+
return rows.map(fromRunEntity);
|
|
1191
|
+
}
|
|
1166
1192
|
async listPendingRuns(limit, namespace) {
|
|
1167
1193
|
const rows = await this.runs().find({
|
|
1168
1194
|
where: {
|
|
@@ -1827,6 +1853,29 @@ function fromScheduleEntity(e) {
|
|
|
1827
1853
|
};
|
|
1828
1854
|
}
|
|
1829
1855
|
__name(fromScheduleEntity, "fromScheduleEntity");
|
|
1856
|
+
function runUpdateSet(patch) {
|
|
1857
|
+
const update = {};
|
|
1858
|
+
if ("workflow" in patch) update.workflow = patch.workflow;
|
|
1859
|
+
if ("workflowVersion" in patch) update.workflowVersion = patch.workflowVersion;
|
|
1860
|
+
if ("status" in patch) update.status = patch.status;
|
|
1861
|
+
if ("input" in patch) update.input = patch.input ?? null;
|
|
1862
|
+
if ("output" in patch) update.output = patch.output ?? null;
|
|
1863
|
+
if ("error" in patch) update.error = patch.error ?? null;
|
|
1864
|
+
if ("wakeAt" in patch) update.wakeAt = patch.wakeAt == null ? null : new Date(patch.wakeAt);
|
|
1865
|
+
if ("lockedBy" in patch) update.lockedBy = patch.lockedBy ?? null;
|
|
1866
|
+
if ("lockedUntil" in patch) update.lockedUntil = patch.lockedUntil == null ? null : new Date(patch.lockedUntil);
|
|
1867
|
+
if ("awaitingDecisionTaskId" in patch) update.awaitingDecisionTaskId = patch.awaitingDecisionTaskId ?? null;
|
|
1868
|
+
if ("recoveryAttempts" in patch) update.recoveryAttempts = patch.recoveryAttempts;
|
|
1869
|
+
if ("tags" in patch) update.tags = patch.tags ?? null;
|
|
1870
|
+
if ("searchAttributes" in patch) update.searchAttributes = patch.searchAttributes ?? null;
|
|
1871
|
+
if ("priority" in patch) update.priority = patch.priority ?? null;
|
|
1872
|
+
if ("namespace" in patch) update.namespace = patch.namespace ?? "default";
|
|
1873
|
+
if ("origin" in patch) update.origin = patch.origin ?? null;
|
|
1874
|
+
if ("createdAt" in patch) update.createdAt = patch.createdAt;
|
|
1875
|
+
if ("updatedAt" in patch) update.updatedAt = patch.updatedAt;
|
|
1876
|
+
return update;
|
|
1877
|
+
}
|
|
1878
|
+
__name(runUpdateSet, "runUpdateSet");
|
|
1830
1879
|
async function updateIfPending(repo, checkpoint) {
|
|
1831
1880
|
const { runId, seq, ...data } = toCheckpointEntity(checkpoint);
|
|
1832
1881
|
const set = {
|