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
Copy file name to clipboardExpand all lines: src/content/docs/workflows/build/rules-of-workflows.mdx
+16-2Lines changed: 16 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -227,7 +227,8 @@ export class MyWorkflow extends WorkflowEntrypoint {
227
227
228
228
### Name steps deterministically
229
229
230
-
Dynamically naming a step will prevent it from being cached, and cause the step to be re-run unnecessarily. Step names act as the "cache key" in your Workflow.
230
+
Steps should be named deterministically (even if dynamic). This ensures that their state is cached, and prevents the step from being rerun unnecessarily. Step names act as the "cache key" in your Workflow.
231
+
231
232
232
233
```ts
233
234
exportclassMyWorkflowextendsWorkflowEntrypoint {
@@ -243,7 +244,20 @@ export class MyWorkflow extends WorkflowEntrypoint {
243
244
// Return dynamic values in your state, or log them instead.
244
245
let state =awaitstep.do("fetch user data from KV", async () => {
245
246
let userData =awaitenv.KV.get(event.user)
246
-
console.log(`fetched at ${Date.now})
247
+
console.log(`fetched at ${Date.now}`)
247
248
returnuserData
248
249
})
250
+
251
+
// ✅ Good: steps that are dynamically named are constructed in a deterministic way.
252
+
// In this case, `catList` is a step output, which is stable, and `catList` is
253
+
// traversed in a deterministic fashion (no shuffles or random accesses) so,
254
+
// it's fine to dynamically name steps (e.g: create a step per list entry).
255
+
let catList =awaitstep.do("get cat list from KV", async () => {
0 commit comments