@dudousxd/nestjs-durable-core 0.44.0 → 0.45.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
@@ -773,7 +773,6 @@ function eventMatches(payload, match) {
773
773
  __name(eventMatches, "eventMatches");
774
774
 
775
775
  // src/remote-workflow-executor.ts
776
- var taskCounter = 0;
777
776
  var RemoteWorkflowExecutor = class {
778
777
  static {
779
778
  __name(this, "RemoteWorkflowExecutor");
@@ -785,15 +784,13 @@ var RemoteWorkflowExecutor = class {
785
784
  this.group = group;
786
785
  }
787
786
  /**
788
- * Dispatch one workflow turn and return its `taskId`. Does NOT await the decision — the engine
789
- * suspends the run on the returned `taskId` and applies the decision durably via `onDecision`.
787
+ * Enqueue one workflow turn under the engine-supplied `taskId`. Does NOT await the decision — the
788
+ * engine has already suspended the run on `taskId` and applies the decision durably via `onDecision`.
790
789
  */
791
- async dispatch(run, history, pendingSignals) {
790
+ async dispatch(run, history, taskId, pendingSignals) {
792
791
  if (!this.transport.dispatchWorkflowTask) {
793
792
  throw new Error("transport does not support workflow tasks (dispatchWorkflowTask)");
794
793
  }
795
- taskCounter += 1;
796
- const taskId = `${run.id}:wf:${taskCounter}`;
797
794
  const task = {
798
795
  taskId,
799
796
  runId: run.id,
@@ -809,9 +806,6 @@ var RemoteWorkflowExecutor = class {
809
806
  attempt: 1
810
807
  };
811
808
  await this.transport.dispatchWorkflowTask(task);
812
- return {
813
- taskId
814
- };
815
809
  }
816
810
  };
817
811
 
@@ -991,6 +985,17 @@ var TransportPool = class {
991
985
  ...groups
992
986
  ];
993
987
  }
988
+ /**
989
+ * Propagate the engine's `namespace` to every transport that partitions by it — so the same
990
+ * namespace that scopes the store also scopes each transport's queues/keys. A transport that
991
+ * doesn't partition (no `useNamespace`) is skipped. Idempotent; a transport given an explicit
992
+ * namespace at construction ignores this (see {@link Transport.useNamespace}).
993
+ */
994
+ useNamespace(namespace) {
995
+ for (const { transport } of this.transports) {
996
+ transport.useNamespace?.(namespace);
997
+ }
998
+ }
994
999
  /** Pinned `preferId` first, then the rest (failover order). */
995
1000
  ordered(preferId) {
996
1001
  if (!preferId) return this.transports;
@@ -1658,6 +1663,7 @@ var WorkflowEngine = class {
1658
1663
  this.admission.onFreed?.((queue) => this.wakeQueueWaiters(queue));
1659
1664
  this.instanceId = deps.instanceId ?? globalThis.crypto.randomUUID();
1660
1665
  this.namespace = deps.namespace ?? "default";
1666
+ this.pool.useNamespace(this.namespace);
1661
1667
  this.leaseMs = deps.leaseMs ?? 3e4;
1662
1668
  this.maxRecoveryAttempts = deps.maxRecoveryAttempts;
1663
1669
  this.remoteAdvanceSilenceMs = deps.remoteAdvanceSilenceMs;
@@ -3000,19 +3006,9 @@ var WorkflowEngine = class {
3000
3006
  }
3001
3007
  const history = await this.remoteHistory(run.id);
3002
3008
  if (remote.executor.dispatch) {
3003
- const { taskId } = await remote.executor.dispatch(run, history);
3009
+ const taskId = `${run.id}:wf:${globalThis.crypto.randomUUID().slice(0, 8)}`;
3004
3010
  const silenceMs = this.remoteAdvanceSilenceMs;
3005
3011
  const wakeAt = silenceMs != null ? this.clock() + silenceMs : void 0;
3006
- const fresh = await this.store.getRun(run.id);
3007
- if (fresh && (fresh.status === "cancelled" || fresh.status === "completed" || fresh.status === "dead")) {
3008
- await this.store.releaseRunLock(run.id);
3009
- return {
3010
- runId: run.id,
3011
- status: fresh.status,
3012
- output: fresh.output,
3013
- error: fresh.error
3014
- };
3015
- }
3016
3012
  await this.store.updateRun(run.id, {
3017
3013
  status: "suspended",
3018
3014
  awaitingDecisionTaskId: taskId,
@@ -3025,6 +3021,7 @@ var WorkflowEngine = class {
3025
3021
  workflow: run.workflow
3026
3022
  });
3027
3023
  await this.store.releaseRunLock(run.id);
3024
+ await remote.executor.dispatch(run, history, taskId);
3028
3025
  return {
3029
3026
  runId: run.id,
3030
3027
  status: "suspended"