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?
No description
10 Replies
alex (he/him)
alex (he/him)OP•4w ago
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. 🤔
elithrar
elithrar•4w ago
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?
alex (he/him)
alex (he/him)OP•4w ago
Option B, is what cf docs document, or am I mistaken here? 🤔 Code taken out of cf docs:
// âś… Good: imageList state is exclusively comprised of step returns - this means that in the event of
// multiple engine lifetimes, imageList will be built accordingly
const imageList: string[] = await Promise.all([
step.do("get first cutest cat from KV", async () => {
return await env.KV.get("cutest-http-cat-1");
}),

step.do("get second cutest cat from KV", async () => {
return await env.KV.get("cutest-http-cat-2");
}),
]);
// âś… Good: imageList state is exclusively comprised of step returns - this means that in the event of
// multiple engine lifetimes, imageList will be built accordingly
const imageList: string[] = await Promise.all([
step.do("get first cutest cat from KV", async () => {
return await env.KV.get("cutest-http-cat-1");
}),

step.do("get second cutest cat from KV", async () => {
return await env.KV.get("cutest-http-cat-2");
}),
]);
elithrar
elithrar•4w ago
I think that’s a mistake - @Seekerdasbatatas To be clear though, the “bad” here isn’t either of your options
elithrar
elithrar•4w ago
You’re ignoring that “bad” is “you have variables that are not the output of a step” -
No description
elithrar
elithrar•4w ago
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
alex (he/him)
alex (he/him)OP•4w ago
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 🤔
Seekerdasbatatas
Seekerdasbatatas•4w ago
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
alex (he/him)
alex (he/him)OP•4w ago
That's because the return value of any step.do() can be max 1MB, but combining multiple step outputs, it can exceed 1MB?
Seekerdasbatatas
Seekerdasbatatas•4w ago
Exactly The upper bound for the list will be the worker memory limit then
Want results from more Discord servers?
Add your server