Skip to content

Commit 52790bd

Browse files
committed
better example of how to manage catch of steps and example
1 parent c235401 commit 52790bd

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/content/docs/workflows/build/sleeping-and-retrying.mdx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,22 @@ export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {
112112
113113
The Workflow instance itself will fail immediately, no further steps will be invoked, and the Workflow will not be retried.
114114
115-
Like other Errors, any uncaught exceptions that propagate to the top level will cause the Workflow to end execution in an Errored state. Catch the `NonRetryableError` to continue Workflow execution:
115+
## Avoid a Workflow instance to fail
116+
117+
Any uncaught exceptions that propagate to the top level, or any steps that reach their retry limit, will cause the Workflow to end execution in an Errored state. However, this may not be intended, as for example, a cleanup of previous step executions may be required.
118+
119+
To allow the Workflow to continue its execution, surround the intended steps that are allowed to fail with a try/catch.
120+
121+
Simple example of a Worflow with a cleanup step:
116122
117123
```ts
118124
...
125+
await step.do('task', async () => {
126+
// work to be done
127+
});
128+
119129
try {
120-
await step.do('task', async () => {
130+
await step.do('non-retryable-task', async () => {
121131
// work not to be retried
122132
throw new NonRetryableError('oh no');
123133
});
@@ -127,8 +137,8 @@ try {
127137
128138
// the Workflow will not fail and will continue its execution
129139
130-
await step.do('next-task', async() => {
131-
// more work to be done
140+
await step.do('cleanup-task', async() => {
141+
// cleanup work, revert execution from 'task' step
132142
});
133143
...
134144
```

0 commit comments

Comments
 (0)