You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* warn users to avoid side effects top level
* add ; and change ' to "
* add awaits
* make text clearer
* Update rules-of-workflows.mdx
---------
Co-authored-by: mia303 <[email protected]>
Copy file name to clipboardExpand all lines: src/content/docs/workflows/build/rules-of-workflows.mdx
+58Lines changed: 58 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -205,6 +205,64 @@ export class MyWorkflow extends WorkflowEntrypoint {
205
205
```
206
206
</TypeScriptExample>
207
207
208
+
### Avoid doing side effects outside of a `step.do`
209
+
210
+
It is not recommended to write code with any side effects outside of steps, unless you would like it to be repeated, because the Workflow engine may restart while an instance is running. If the engine restarts, the step logic will be preserved, but logic outside of the steps may be duplicated.
211
+
212
+
For example, a `console.log()` outside of workflow steps may cause the logs to print twice when the engine restarts.
213
+
214
+
However, logic involving non-serializable resources, like a database connection, should be executed outside of steps. Operations ouside of a `step.do` might be repeated more than once, due to the nature of the Workflows' instance lifecycle.
The `event` passed to your Workflow's `run` method is immutable: changes you make to the event are not persisted across steps and/or Workflow restarts.
0 commit comments