You never wait on a child workflow, so the workflow just completes immediately. You should at least confirm the child workflow got started without error much less actually runs without error. Something like this:
func SimpleWorkflow(ctx workflow.Context, u []uuid.UUID) error {
if workflow.GetInfo(ctx).ContinuedExecutionRunID == "" {
if err := workflow.ExecuteActivity(workflow.WithActivityOptions(ctx, workflow.ActivityOptions{StartToCloseTimeout: 10 * time.Minute}), SimpleActivity).Get(ctx, &u); err != nil {
return err
}
}
// Only do the first N, then continue as new with the rest
const amountToHandle = 5
toHandle := u
if len(toHandle) > amountToHandle {
toHandle = toHandle[:amountToHandle]
}
selector := workflow.NewSelector(ctx)
var err error
// Start the children
for _, p := range toHandle {
selector.AddFuture(workflow.ExecuteChildWorkflow(ctx, SimpleChildWorkflow, p), func(f workflow.Future) {
err = f.Get(ctx, nil)
})
}
// Wait for all children to complete successfully
for range toHandle {
selector.Select(ctx)
if err != nil {
return err
}
}
// Return continue as new if there are more
if len(u) > amountToHandle {
return workflow.NewContinueAsNewError(ctx, SimpleWorkflow, u[amountToHandle:])
}
return nil
}
You probably shouldn’t run 10k child workflows like this in a single run due to history size limits and input param limits. You should probably batch it up a bit differently on the caller side.
Doesn’t that mean that the parent workflow will wait until the child workflow is completed?
Not sure I understand the question exactly. Basically if you call “Future.Get()” in a workflow, it waits for “Get()” to complete. If that “Get()” is on a child future, it will wait for the child workflow to complete. If you want to wait for the child workflow to start, use “GetChildWorkflowExecution().Get()” on the child future.