Nested steps

Heya 👋 quick question to confirm my understanding: do nested steps behave identical to non-nested ones with regards to cache usage after failures? Specifically, if a nested step fails, would the cached results from all parent steps be reused? Or is the caching of parent steps tied to the success of the (most) inner step(s) somehow?
12 Replies
Seekerdasbatatas
Seekerdasbatatas•4w ago
by nested steps, you mean this?
await step.do('outer', async () => {
await step.do('inner', async () => {

})
})
await step.do('outer', async () => {
await step.do('inner', async () => {

})
})
Timo Reimann
Timo ReimannOP•4w ago
Yes
Seekerdasbatatas
Seekerdasbatatas•4w ago
This is a pattern that I don't know if I would recommend to use 😅 - but I think that the caching of the parent steps are tied to the success of the inner ones
Timo Reimann
Timo ReimannOP•4w ago
Hmm yeah it guess it's not super useful when the outer and inner steps' fates are tied (which actually makes sense to be the case).
Seekerdasbatatas
Seekerdasbatatas•4w ago
for curiosity’s sake, why do you want to do nested steps?
Timo Reimann
Timo ReimannOP•4w ago
The use case I have in mind is where you invoke an external API that returns a list, and then for each result or so you may need to invoke another API. Trying to think how to model that best and wondered if nesting would be helpful here or not.
Seekerdasbatatas
Seekerdasbatatas•4w ago
then I would do something like this:
const results = step.do('get list', async () => {
return ["this", "is", "a", "list", "of", "results"]
})

await Promise.all(results.map((val) => step.do(`call another api for: ${val}`, async () => {
return await fetch('another-api-call')
}))
const results = step.do('get list', async () => {
return ["this", "is", "a", "list", "of", "results"]
})

await Promise.all(results.map((val) => step.do(`call another api for: ${val}`, async () => {
return await fetch('another-api-call')
}))
you also get concurrency (for I/O tasks) for free in this case 🙂
Timo Reimann
Timo ReimannOP•4w ago
Nice, that looks elegant. I suppose that would cache succeeded steps at the per-val level even if one of the many calls eventually failed?
Seekerdasbatatas
Seekerdasbatatas•4w ago
yes, exactly
Timo Reimann
Timo ReimannOP•4w ago
Great, thanks Luís.
Focux
Focux•6d ago
FYI, when creating a workflow with an empty ID, it throws an error I guess that's a bug because the docs say that the ID is optional Also, when you create a workflow, the id property of the workflow is undefined Also, is there a way to get the workflow id from within a workflow? And is there any way to make the params from workflow.create() typed?
Timo Reimann
Timo ReimannOP•6d ago
The empty ID problem is well-known, see multiple other mentions in this channel. the workflow run method has a signature like this:
async run(event: WorkflowEvent<Params>, step: WorkflowStep)
async run(event: WorkflowEvent<Params>, step: WorkflowStep)
<Params> can be your custom type that you can also use on the caller site. it's probably best for you to ask questions unrelated to the topic of this thread in the main channel.
Want results from more Discord servers?
Add your server