@dudousxd/nestjs-durable-store-mikro-orm 0.33.7 → 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 +39 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +40 -11
- 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);
|