My requirement,
- The main workflow receives input.
- Splits the input and for each part executes child workflow.
- Child workflows are executed in parallel.
- The main workflow waits for a specific duration and returns the result of the child workflows that have been completed.
- The remaining child workflows continue to execute and eventually completes.
What is the recommended way of doing it? I am using the code:
public List<String> execute(String flowType, String feedPayload) {
List<String> itemPayloads = parseFeedPayload(feedPayload);
List<Promise<String>> promises = new ArrayList<>(itemPayloads.size());
List<String> responses = new ArrayList<>(itemPayloads.size());
ChildWorkflowOptions itemSetupWorkflowOptions = ChildWorkflowOptions.newBuilder()
.setParentClosePolicy(ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON)
.setWorkflowExecutionTimeout(Duration.ofSeconds(10))
.setRetryOptions(retryoptions)
.setTaskQueue(TASK_QUEUE)
.build();
for (String itemPayload : itemPayloads) {
ItemSetupWorkflow itemSetupWorkflow = Workflow.newChildWorkflowStub(ItemSetupWorkflow.class, itemSetupWorkflowOptions);
Promise<String> promise = Async.function(itemSetupWorkflow::execute, flowType, itemPayload);
promises.add(promise);
}
try {
Promise.allOf(promises).get(2000, TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
e.printStackTrace();
}
for (Promise<String> promise : promises) {
if (promise.isCompleted()) {
responses.add(promise.get());
} else {
responses.add("timeout");
}
}
return responses;
}
get() is a blocking call. What will be the impact on the overall system performance and throughput if I need to execute many such workflows concurrently?
Looks like Promise.get(long var1, TimeUnit var3) does not use var3. The code uses Duration.ofMillis(timeout). Not sure if I missed something here.