@dudousxd/nestjs-durable-store-mikro-orm 0.33.6 → 0.33.8
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 +53 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +54 -22
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -1139,19 +1139,48 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
|
|
|
1139
1139
|
});
|
|
1140
1140
|
}
|
|
1141
1141
|
async tryAdmitSingleton(runId, tag, workflow, limit, retryWakeAt) {
|
|
1142
|
+
const where = {
|
|
1143
|
+
workflow,
|
|
1144
|
+
status: {
|
|
1145
|
+
$in: import_nestjs_durable_core.SINGLETON_ACTIVE_STATUSES
|
|
1146
|
+
},
|
|
1147
|
+
...this.scopeNamespace !== void 0 ? {
|
|
1148
|
+
namespace: this.scopeNamespace
|
|
1149
|
+
} : {}
|
|
1150
|
+
};
|
|
1151
|
+
const reader = this.fork();
|
|
1152
|
+
const sqlite = /sqlite|libsql/i.test(reader.getPlatform().constructor.name);
|
|
1153
|
+
const claimants = sqlite ? [] : (0, import_nestjs_durable_core.singletonClaimantIds)(await reader.find(WorkflowRunEntity, where, {
|
|
1154
|
+
fields: [
|
|
1155
|
+
"id",
|
|
1156
|
+
"tags"
|
|
1157
|
+
],
|
|
1158
|
+
orderBy: {
|
|
1159
|
+
id: "ASC"
|
|
1160
|
+
},
|
|
1161
|
+
// The primary: a lagging replica would leave rows out of the lock set.
|
|
1162
|
+
connectionType: "write"
|
|
1163
|
+
}), tag);
|
|
1142
1164
|
return this.fork().transactional(async (em) => {
|
|
1143
|
-
|
|
1144
|
-
workflow,
|
|
1145
|
-
status: {
|
|
1146
|
-
$in: import_nestjs_durable_core.SINGLETON_ACTIVE_STATUSES
|
|
1147
|
-
},
|
|
1148
|
-
...this.scopeNamespace !== void 0 ? {
|
|
1149
|
-
namespace: this.scopeNamespace
|
|
1150
|
-
} : {}
|
|
1151
|
-
};
|
|
1152
|
-
await em.nativeUpdate(WorkflowRunEntity, where, {
|
|
1165
|
+
if (sqlite) await em.nativeUpdate(WorkflowRunEntity, where, {
|
|
1153
1166
|
workflow
|
|
1154
1167
|
});
|
|
1168
|
+
for (let at = 0; at < claimants.length; at += import_nestjs_durable_core.SINGLETON_LOCK_CHUNK) {
|
|
1169
|
+
await em.find(WorkflowRunEntity, {
|
|
1170
|
+
id: {
|
|
1171
|
+
$in: claimants.slice(at, at + import_nestjs_durable_core.SINGLETON_LOCK_CHUNK)
|
|
1172
|
+
}
|
|
1173
|
+
}, {
|
|
1174
|
+
fields: [
|
|
1175
|
+
"id"
|
|
1176
|
+
],
|
|
1177
|
+
orderBy: {
|
|
1178
|
+
id: "ASC"
|
|
1179
|
+
},
|
|
1180
|
+
lockMode: import_core3.LockMode.PESSIMISTIC_WRITE
|
|
1181
|
+
});
|
|
1182
|
+
}
|
|
1183
|
+
em.clear();
|
|
1155
1184
|
const rows = await em.find(WorkflowRunEntity, where);
|
|
1156
1185
|
const runs = rows.map(fromRunEntity);
|
|
1157
1186
|
const tags = (0, import_nestjs_durable_core.singletonAdmissionTags)(runs, runId, tag, workflow, limit);
|
|
@@ -1176,22 +1205,25 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
|
|
|
1176
1205
|
});
|
|
1177
1206
|
}
|
|
1178
1207
|
async createRun(run) {
|
|
1179
|
-
|
|
1180
|
-
em.create(WorkflowRunEntity, toRunEntity(run));
|
|
1181
|
-
await em.flush();
|
|
1208
|
+
await this.fork().insert(WorkflowRunEntity, toRunEntity(run));
|
|
1182
1209
|
await this.reindexAttributes(run.id, run.searchAttributes);
|
|
1183
1210
|
}
|
|
1184
1211
|
async updateRun(runId, inputPatch) {
|
|
1185
1212
|
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.withScope({}).getRun(id)) : inputPatch;
|
|
1213
|
+
const data = runUpdateData(patch);
|
|
1186
1214
|
const em = this.fork();
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1215
|
+
if (Object.keys(data).length) {
|
|
1216
|
+
const affected = await em.nativeUpdate(WorkflowRunEntity, {
|
|
1217
|
+
id: runId
|
|
1218
|
+
}, data);
|
|
1219
|
+
if (affected === 0) await em.findOneOrFail(WorkflowRunEntity, {
|
|
1220
|
+
id: runId
|
|
1221
|
+
});
|
|
1222
|
+
} else {
|
|
1223
|
+
await em.findOneOrFail(WorkflowRunEntity, {
|
|
1224
|
+
id: runId
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1195
1227
|
if ("searchAttributes" in patch) await this.reindexAttributes(runId, patch.searchAttributes);
|
|
1196
1228
|
}
|
|
1197
1229
|
async updateRunIf(runId, expectedStatuses, inputPatch) {
|