@dudousxd/nestjs-durable-core 0.85.10 → 0.85.11

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.d.cts CHANGED
@@ -6270,10 +6270,17 @@ declare class WorkflowEngine {
6270
6270
  * result may have landed since. The fan's last turn so reads nothing it already read.
6271
6271
  */
6272
6272
  private fanCheckpoints;
6273
+ /** Write a round of a step fan's checkpoints: one call where the store batches, else chunked. */
6274
+ private saveFanCheckpoints;
6273
6275
  /**
6274
- * Write the `pending` checkpoints of a step fan's new steps, then dispatch them: one
6275
- * {@link StateStore.saveCheckpoints} call and one {@link TransportPool.dispatchMany} for the
6276
- * batch, where the store and transport have them.
6276
+ * Write the `pending` checkpoints of a step fan's new steps and dispatch them, in rounds of
6277
+ * {@link STEP_FAN_SEND_ROUND}: a round's steps are dispatched once its checkpoints commit, while the
6278
+ * next round's are written. One {@link StateStore.saveCheckpoints} call and one
6279
+ * {@link TransportPool.dispatchMany} per round, where the store and transport have them.
6280
+ *
6281
+ * No result can wake the run before every round is written: the run is `running` under this
6282
+ * turn's lease until the turn suspends. A send cut short leaves the unwritten steps without a
6283
+ * checkpoint, and the replay sends them once the written ones settle.
6277
6284
  */
6278
6285
  private sendStepFan;
6279
6286
  /** Remember a step settled here, forgetting entries older than a lease so the map stays small. */
package/dist/index.d.ts CHANGED
@@ -6270,10 +6270,17 @@ declare class WorkflowEngine {
6270
6270
  * result may have landed since. The fan's last turn so reads nothing it already read.
6271
6271
  */
6272
6272
  private fanCheckpoints;
6273
+ /** Write a round of a step fan's checkpoints: one call where the store batches, else chunked. */
6274
+ private saveFanCheckpoints;
6273
6275
  /**
6274
- * Write the `pending` checkpoints of a step fan's new steps, then dispatch them: one
6275
- * {@link StateStore.saveCheckpoints} call and one {@link TransportPool.dispatchMany} for the
6276
- * batch, where the store and transport have them.
6276
+ * Write the `pending` checkpoints of a step fan's new steps and dispatch them, in rounds of
6277
+ * {@link STEP_FAN_SEND_ROUND}: a round's steps are dispatched once its checkpoints commit, while the
6278
+ * next round's are written. One {@link StateStore.saveCheckpoints} call and one
6279
+ * {@link TransportPool.dispatchMany} per round, where the store and transport have them.
6280
+ *
6281
+ * No result can wake the run before every round is written: the run is `running` under this
6282
+ * turn's lease until the turn suspends. A send cut short leaves the unwritten steps without a
6283
+ * checkpoint, and the replay sends them once the written ones settle.
6277
6284
  */
6278
6285
  private sendStepFan;
6279
6286
  /** Remember a step settled here, forgetting entries older than a lease so the map stays small. */
package/dist/index.js CHANGED
@@ -4815,6 +4815,7 @@ var VERSION_UNDECLARED_TAG = "version:undeclared";
4815
4815
  var versionKey = /* @__PURE__ */ __name((name, version) => `${name}@${version}`, "versionKey");
4816
4816
  var STEP_FAN_CHUNK = 200;
4817
4817
  var FAN_REREAD_CHUNK = 1e3;
4818
+ var STEP_FAN_SEND_ROUND = 2e3;
4818
4819
  var PARENT_NOTIFY_ATTEMPTS = 4;
4819
4820
  var PARENT_NOTIFY_BACKOFF_MS = 250;
4820
4821
  var LEASE_RECHECK_MAX_MS = 2e3;
@@ -10225,10 +10226,25 @@ ${run.workflowVersion}`;
10225
10226
  }
10226
10227
  return bySeq;
10227
10228
  }
10229
+ /** Write a round of a step fan's checkpoints: one call where the store batches, else chunked. */
10230
+ async saveFanCheckpoints(checkpoints) {
10231
+ if (this.store.saveCheckpoints) {
10232
+ await this.store.saveCheckpoints(checkpoints);
10233
+ return;
10234
+ }
10235
+ for (let at = 0; at < checkpoints.length; at += STEP_FAN_CHUNK) {
10236
+ await Promise.all(checkpoints.slice(at, at + STEP_FAN_CHUNK).map((cp) => this.store.saveCheckpoint(cp)));
10237
+ }
10238
+ }
10228
10239
  /**
10229
- * Write the `pending` checkpoints of a step fan's new steps, then dispatch them: one
10230
- * {@link StateStore.saveCheckpoints} call and one {@link TransportPool.dispatchMany} for the
10231
- * batch, where the store and transport have them.
10240
+ * Write the `pending` checkpoints of a step fan's new steps and dispatch them, in rounds of
10241
+ * {@link STEP_FAN_SEND_ROUND}: a round's steps are dispatched once its checkpoints commit, while the
10242
+ * next round's are written. One {@link StateStore.saveCheckpoints} call and one
10243
+ * {@link TransportPool.dispatchMany} per round, where the store and transport have them.
10244
+ *
10245
+ * No result can wake the run before every round is written: the run is `running` under this
10246
+ * turn's lease until the turn suspends. A send cut short leaves the unwritten steps without a
10247
+ * checkpoint, and the replay sends them once the written ones settle.
10232
10248
  */
10233
10249
  async sendStepFan(runId, positions, step, inputs, batch, group, opts, routing) {
10234
10250
  const workerGroup = stepGroup(step, routing?.namespace);
@@ -10256,27 +10272,33 @@ ${run.workflowVersion}`;
10256
10272
  } : {}
10257
10273
  };
10258
10274
  });
10259
- if (this.store.saveCheckpoints) {
10260
- await this.store.saveCheckpoints(checkpoints);
10261
- } else {
10262
- for (let at = 0; at < checkpoints.length; at += STEP_FAN_CHUNK) {
10263
- await Promise.all(checkpoints.slice(at, at + STEP_FAN_CHUNK).map((cp) => this.store.saveCheckpoint(cp)));
10264
- }
10265
- }
10266
10275
  const traceparent = this.traceparent?.();
10267
10276
  const context = this.context?.();
10268
- await this.pool.dispatchMany(checkpoints.map((cp, k) => ({
10269
- runId,
10270
- seq: cp.seq,
10271
- name: step.name,
10272
- stepId: cp.stepId,
10273
- group: workerGroup,
10274
- input: inputs[batch[k]],
10275
- traceparent,
10276
- context,
10277
- priority: opts.admission?.priority,
10278
- attempt: 1
10279
- })), opts.transport);
10277
+ const dispatches = [];
10278
+ try {
10279
+ for (let from = 0; from < checkpoints.length; from += STEP_FAN_SEND_ROUND) {
10280
+ const round = checkpoints.slice(from, from + STEP_FAN_SEND_ROUND);
10281
+ await this.saveFanCheckpoints(round);
10282
+ const dispatch = this.pool.dispatchMany(round.map((cp, k) => ({
10283
+ runId,
10284
+ seq: cp.seq,
10285
+ name: step.name,
10286
+ stepId: cp.stepId,
10287
+ group: workerGroup,
10288
+ input: inputs[batch[from + k]],
10289
+ traceparent,
10290
+ context,
10291
+ priority: opts.admission?.priority,
10292
+ attempt: 1
10293
+ })), opts.transport);
10294
+ dispatch.catch(() => {
10295
+ });
10296
+ dispatches.push(dispatch);
10297
+ }
10298
+ } finally {
10299
+ await Promise.allSettled(dispatches);
10300
+ }
10301
+ await Promise.all(dispatches);
10280
10302
  for (const cp of checkpoints) {
10281
10303
  this.emit({
10282
10304
  type: "step.started",