-
Notifications
You must be signed in to change notification settings - Fork 501
Description
I have an app with a multistep workflow, for which I find the FlowProducer feature to be perfect for sequencing each step, and keeping everything robust when dealing with flaky APIs.
However, I find the interface for creating these flows to be awkward to both write and read, since they are essentially declared backwards:
await flowProducer.add({
name: 'eat-veggies',
children: [
{
name: 'roast-veggies',
children: [
{
name: 'chop-veggies',
}
]
}
]
})
I would prefer if I was able to define these flows as a simple sequence of steps, i.e.:
await flowProducer.add([
{
name: 'chop-veggies',
},
{
name: 'roast-veggies',
},
{
name: 'eat-veggies',
},
]
)
or possibly even with a fluent interface/builder pattern, e.g.
await flowProducer.add(
makeFlowOrSomething()
.addStep("chop-veggies")
.addStep("roast-veggies")
.addStep("eat-veggies")
)
I've currently using my own hand-rolled helper function to do this
interface FlowNode {
name: string;
queueName: string;
data: any;
children?: FlowNode[];
}
function buildFlow(
firstStep: FlowNode,
...remainingSteps: FlowNode[]
): FlowJob {
let root: FlowNode = firstStep;
for (const step of remainingSteps) {
root = { ...step, children: [...(step.children ?? []), root] };
}
return root;
}
But I think it would be really nice if this were part of the library. Is there any reason not to take this approach?
It doesn't have to only apply to purely sequential flows as we could still have sibling nodes which run in parallel, e.g.:
await flows.add([
{
name: 'chop-veggies'
},
[
{
name: 'roast-veggies'
},
{
name: 'set-table'
}
],
{
name: 'eat-veggies'
}
])
Excuse me if we already have something like this, I looked around and couldn't find it anywhere.