Workflows makes it easier to build reliable multi-step applications that can recover when downstream systems fail. Rollback handlers now receive the original step context via a ctx object for the step being rolled back. This includes ctx.step.name, ctx.step.count, ctx.attempt, and the step config with defaults applied.
The step configuration includes the retry and timeout settings used for that step, so you can customize your step recovery logic according to those fields.
await step.do( "create charge", async () => { const charge = await createCharge(); return { chargeId: charge.id }; }, { rollback: async ({ ctx, output, error }) => { // `output` is the value returned by the step being rolled back. const { chargeId } = output as { chargeId: string }; await refundCharge(chargeId, { // `ctx` is the original step context, including step name, count, attempt, and config. reason: `${ctx.step.name}: ${error.message}`, }); }, rollbackConfig: { // `rollbackConfig` controls retries and timeout for the rollback handler. retries: { limit: 3, delay: "30 seconds", backoff: "linear" }, timeout: "5 minutes", }, },);Refer to rollback options to learn more.
Source: Cloudflare





