@dudousxd/nestjs-durable-store-mikro-orm 0.31.0 → 0.32.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 CHANGED
@@ -980,6 +980,7 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
980
980
  }, {
981
981
  status: "suspended",
982
982
  wakeAt: new Date(patch.wakeAt),
983
+ tags: patch.tags,
983
984
  updatedAt: patch.updatedAt
984
985
  });
985
986
  return false;
@@ -1199,7 +1200,7 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
1199
1200
  });
1200
1201
  return rows.map(fromRunEntity);
1201
1202
  }
1202
- async listOrphanedRuns(nowMs, limit, namespace) {
1203
+ async listOrphanedRuns(nowMs, limit, namespace, ownedBy) {
1203
1204
  if (limit <= 0) return [];
1204
1205
  const em = this.fork();
1205
1206
  const rows = await em.find(WorkflowRunEntity, {
@@ -1217,7 +1218,16 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
1217
1218
  lockedUntil: {
1218
1219
  $lte: new Date(nowMs)
1219
1220
  }
1220
- }
1221
+ },
1222
+ // A live lease left by a previous process with the caller's own instance id.
1223
+ ...ownedBy ? [
1224
+ {
1225
+ lockedBy: ownedBy.owner,
1226
+ lockedUntil: {
1227
+ $lt: new Date(ownedBy.lockedBefore)
1228
+ }
1229
+ }
1230
+ ] : []
1221
1231
  ],
1222
1232
  ...namespace !== void 0 ? {
1223
1233
  namespace
@@ -1621,7 +1631,7 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
1621
1631
  * single statement. */
1622
1632
  async updateSchedule(id, patch, expectedNextFireAt) {
1623
1633
  const data = {};
1624
- if (patch.namespace !== void 0) data.namespace = patch.namespace;
1634
+ if (patch.namespace !== void 0) data.namespace = patch.namespace || "default";
1625
1635
  if (patch.workflow !== void 0) data.workflow = patch.workflow;
1626
1636
  if (patch.paused !== void 0) data.paused = patch.paused;
1627
1637
  if ("nextFireAt" in patch) data.nextFireAt = patch.nextFireAt ?? null;
@@ -2007,7 +2017,7 @@ function runUpdateData(patch) {
2007
2017
  if ("tags" in patch) data.tags = patch.tags ?? null;
2008
2018
  if ("searchAttributes" in patch) data.searchAttributes = patch.searchAttributes ?? null;
2009
2019
  if ("priority" in patch) data.priority = patch.priority ?? null;
2010
- if ("namespace" in patch) data.namespace = patch.namespace ?? "default";
2020
+ if ("namespace" in patch) data.namespace = patch.namespace || "default";
2011
2021
  if ("origin" in patch) data.origin = patch.origin ?? null;
2012
2022
  if (patch.createdAt != null) data.createdAt = patch.createdAt;
2013
2023
  if (patch.updatedAt != null) data.updatedAt = patch.updatedAt;
@@ -2031,7 +2041,7 @@ function toRunEntity(run) {
2031
2041
  e.tags = run.tags ?? null;
2032
2042
  e.searchAttributes = run.searchAttributes ?? null;
2033
2043
  e.priority = run.priority ?? null;
2034
- e.namespace = run.namespace ?? "default";
2044
+ e.namespace = run.namespace || "default";
2035
2045
  e.origin = run.origin ?? null;
2036
2046
  e.createdAt = run.createdAt;
2037
2047
  e.updatedAt = run.updatedAt;