@dudousxd/nestjs-durable-core 0.104.0 → 0.105.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
@@ -246,6 +246,7 @@ __export(index_exports, {
246
246
  resolveWireTenant: () => resolveWireTenant,
247
247
  retentionKeeps: () => retentionKeeps,
248
248
  retiredHandoffName: () => retiredHandoffName,
249
+ retryLocalStep: () => retryLocalStep,
249
250
  routeFor: () => routeFor,
250
251
  rowTenant: () => rowTenant,
251
252
  runCompletedEvent: () => runCompletedEvent,
@@ -981,6 +982,27 @@ function backoffDelay(attempt, options) {
981
982
  return options?.jitter ? Math.round(capped * (0.5 + Math.random() * 0.5)) : capped;
982
983
  }
983
984
  __name(backoffDelay, "backoffDelay");
985
+ async function retryLocalStep(options, attempt) {
986
+ const maxAttempts = Math.max(1, options?.retries ?? 1);
987
+ for (let n = 1; ; n += 1) {
988
+ try {
989
+ return {
990
+ ok: true,
991
+ value: await attempt(n),
992
+ attempts: n
993
+ };
994
+ } catch (error2) {
995
+ if (error2 instanceof FatalError || n >= maxAttempts) return {
996
+ ok: false,
997
+ error: error2,
998
+ attempts: n
999
+ };
1000
+ const wait = backoffDelay(n, options);
1001
+ if (wait > 0) await new Promise((resolve) => setTimeout(resolve, wait));
1002
+ }
1003
+ }
1004
+ }
1005
+ __name(retryLocalStep, "retryLocalStep");
984
1006
 
985
1007
  // src/bounded-runner.ts
986
1008
  var BoundedRunner = class {
@@ -6210,7 +6232,6 @@ function createWorkflowCtx(host, runId, compensations, workflow = "", searchAttr
6210
6232
  });
6211
6233
  return existing.output;
6212
6234
  }
6213
- const maxAttempts = Math.max(1, options?.retries ?? 1);
6214
6235
  const startedAt = /* @__PURE__ */ new Date();
6215
6236
  await host.startStep({
6216
6237
  runId,
@@ -6221,60 +6242,59 @@ function createWorkflowCtx(host, runId, compensations, workflow = "", searchAttr
6221
6242
  enqueuedAt: startedAt,
6222
6243
  startedAt
6223
6244
  });
6224
- for (let attempt = 1; ; attempt += 1) {
6225
- const events = [];
6226
- try {
6227
- const invocation = {
6228
- runId,
6229
- workflow,
6230
- stepName: name,
6231
- seq: current,
6232
- attempt
6233
- };
6234
- const body = /* @__PURE__ */ __name(() => {
6235
- const logger = createStepLogger(events, host.clock);
6236
- return runInStepScope(scopeOwner, name, () => runInStepLogger(logger, () => fn(logger)));
6237
- }, "body");
6238
- const output = host.interceptStep ? await host.interceptStep(invocation, body) : await body();
6239
- await host.completeStep({
6240
- runId,
6241
- seq: current,
6242
- name,
6243
- kind: "local",
6244
- output,
6245
- events,
6246
- attempts: attempt,
6247
- enqueuedAt: startedAt,
6248
- startedAt
6249
- });
6250
- if (options?.compensate) compensations.push({
6251
- name,
6252
- fn: options.compensate
6253
- });
6254
- return output;
6255
- } catch (err) {
6256
- if (err instanceof FatalError || attempt >= maxAttempts) {
6257
- await host.failStep({
6258
- runId,
6259
- seq: current,
6260
- name,
6261
- kind: "local",
6262
- error: {
6263
- message: err instanceof Error ? err.message : String(err),
6264
- stack: err instanceof Error ? err.stack : void 0,
6265
- ...codeAndDetails(err)
6266
- },
6267
- events,
6268
- attempts: attempt,
6269
- enqueuedAt: startedAt,
6270
- startedAt
6271
- });
6272
- throw err;
6273
- }
6274
- const wait = backoffDelay(attempt, options);
6275
- if (wait > 0) await new Promise((resolve) => setTimeout(resolve, wait));
6276
- }
6245
+ let events = [];
6246
+ const outcome = await retryLocalStep(options, async (attempt) => {
6247
+ const attemptEvents = [];
6248
+ events = attemptEvents;
6249
+ const invocation = {
6250
+ runId,
6251
+ workflow,
6252
+ stepName: name,
6253
+ seq: current,
6254
+ attempt
6255
+ };
6256
+ const body = /* @__PURE__ */ __name(() => {
6257
+ const logger = createStepLogger(attemptEvents, host.clock);
6258
+ return runInStepScope(scopeOwner, name, () => runInStepLogger(logger, () => fn(logger)));
6259
+ }, "body");
6260
+ const output = host.interceptStep ? await host.interceptStep(invocation, body) : await body();
6261
+ await host.completeStep({
6262
+ runId,
6263
+ seq: current,
6264
+ name,
6265
+ kind: "local",
6266
+ output,
6267
+ events: attemptEvents,
6268
+ attempts: attempt,
6269
+ enqueuedAt: startedAt,
6270
+ startedAt
6271
+ });
6272
+ return output;
6273
+ });
6274
+ if (outcome.ok) {
6275
+ if (options?.compensate) compensations.push({
6276
+ name,
6277
+ fn: options.compensate
6278
+ });
6279
+ return outcome.value;
6277
6280
  }
6281
+ const err = outcome.error;
6282
+ await host.failStep({
6283
+ runId,
6284
+ seq: current,
6285
+ name,
6286
+ kind: "local",
6287
+ error: {
6288
+ message: err instanceof Error ? err.message : String(err),
6289
+ stack: err instanceof Error ? err.stack : void 0,
6290
+ ...codeAndDetails(err)
6291
+ },
6292
+ events,
6293
+ attempts: outcome.attempts,
6294
+ enqueuedAt: startedAt,
6295
+ startedAt
6296
+ });
6297
+ throw err;
6278
6298
  }, "localStep");
6279
6299
  const transaction = /* @__PURE__ */ __name(async (name, fn) => {
6280
6300
  if (!store.transaction) {
@@ -14403,7 +14423,7 @@ ${run.workflowVersion}`;
14403
14423
  output: cmd.output,
14404
14424
  error: cmd.error,
14405
14425
  events: cmd.events,
14406
- attempts: 1,
14426
+ attempts: cmd.attempts ?? 1,
14407
14427
  enqueuedAt: startedAt,
14408
14428
  startedAt,
14409
14429
  finishedAt,
@@ -19434,6 +19454,7 @@ __name(settleResultsWithPlainCalls, "settleResultsWithPlainCalls");
19434
19454
  resolveWireTenant,
19435
19455
  retentionKeeps,
19436
19456
  retiredHandoffName,
19457
+ retryLocalStep,
19437
19458
  routeFor,
19438
19459
  rowTenant,
19439
19460
  runCompletedEvent,