Hello, just getting started with Temporal and trying to re-architect my microservices into workflows.
I’m trying to understand the best pattern to trigger async child workflows that return a value to the parent workflow which needs to collate the net result and make a decision.
Each child workflow is independent to others so should be run in parallel.
As each analysis takes about 3seconds to complete.
And there may be 20 analysis to run on 1 dataset.
The net result need to be calculated as fast as possible.
EDIT: after some more research this post on SO by maxim seems to be the idea SO post
Some pseudo-code to explain more clearly hopefully.
workflow getNetResult ( dataSet1 ) {
activeAnalysis = [ ]
activeAnalysis = getActiveAnalysisForDataSet( dataSet1 )
// activeAnalysis = [ analysis1, analysis2 ... ]
analysisResults = [ ]
for each activeAnalysis {
// the below should all be run async at same time
// rather than waiting for each one to complete
analysisResult = workflow.run( analysis1, dataSet1 )
}
// wait for a signal from child workflows
// some may complete fast other slower
workflow.signalChannel(signalChannelName).Receive( analysisValue )
// analysisValue = +2 or -1 etc..
analysisResults.push( analysisValue )
// some check to see if all the workflows have triggered?
// probably by removing the analysis name from
// the activeAnalysis array until empty
// wait for all analysis workflows to complete
netResult = sumEachElement( analysisResults )
saveToDB(netResult)
}
Any advice would be much appreciated
Cheers