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?
10 Replies
Seekerdasbatatas
Seekerdasbatatas•3w 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•3w ago
Yes
Seekerdasbatatas
Seekerdasbatatas•3w 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•3w 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•3w ago
for curiosity’s sake, why do you want to do nested steps?
Timo Reimann
Timo ReimannOP•3w 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•3w 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•3w 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•3w ago
yes, exactly
Timo Reimann
Timo ReimannOP•3w ago
Great, thanks Luís.
Want results from more Discord servers?
Add your server