And does anyone has thoughts about these
And does anyone has thoughts about these two options. Is there any difference between them, and if so what is the difference?
10 Replies
One follows the recommended pattern in docs: https://developers.cloudflare.com/workflows/build/rules-of-workflows/#do-not-rely-on-state-outside-of-a-step
The other follows the nested step pattern often found here or on Twitter. 🤔
Option A.
Your
results
variable in OptionB breaks the rules in that doc
Can you help me understand why you want OptionB here? What are you trying to achieve?Option B, is what cf docs document, or am I mistaken here? 🤔
Code taken out of cf docs:
I think that’s a mistake - @Seekerdasbatatas
To be clear though, the “bad” here isn’t either of your options
You’re ignoring that “bad” is “you have variables that are not the output of a step” -
Nesting steps within a step - and having that step return state - is OK.
This means that you should not store state outside of a step
I understood that limitation, and it make sense, because it would get lost. But I think both of my options, don't have that issue. So now I'm wondering the difference between having one "wrapper" step state which returns the array of other steps states, or directly assigning the array of other step states to the variable, if there is any 🤔
You can have state outside steps, as long it's constructed deterministically with constants or step outputs. I prefer the second approach (pMap of step.do()), because this way, the list be bigger than 1MB
But assuming that you don't have this constraint, both approaches are equivalent
That's because the return value of any
step.do()
can be max 1MB, but combining multiple step outputs, it can exceed 1MB?Exactly
The upper bound for the list will be the worker memory limit then