Hi there.
I have a workflow that works more or less like this:
[Workflow("indexing_orchestrator")]
public class IndexingOrchestratorWorkflow
{
private List<(ChildWorkflowHandle, Task)> ongoingWorkflows = new();
[WorkflowInit]
public IndexingOrchestratorWorkflow(IndexingOrchestratorWorkflowInput input)
{
//?!
}
[WorkflowRun]
public async Task RunAsync(IndexingOrchestratorWorkflowInput _)
{
while (!Workflow.ContinueAsNewSuggested)
{
IndexingRetrieveRequestsActivityOutput newRequests;
//execute an activity to get new requests from somewhere
foreach (var request in newRequests.Requests)
{
var wfHandle = await Workflow.StartChildWorkflowAsync(...,
new()
{
Id = ...,
ParentClosePolicy = ParentClosePolicy.Abandon,
});
this.ongoingWorkflows.Add((wfHandle, wfHandle.GetResultAsync()));
}
// wait for any to finish
await WorkflowWrapper.WhenAnySafe(this.ongoingWorkflows.Select(t =>
{
t.Item2.ConfigureAwait(true);
return t.Item2;
}));
this.ongoingWorkflows.RemoveAll(t => t.Item2.IsCompleted);
}
await Workflow.WaitConditionAsync(() => Workflow.AllHandlersFinished);
// must continue as new if requests are ongoing
if (this.ongoingWorkflows.Count > 0)
{
var newInput = //???;
throw Workflow.CreateContinueAsNewException((IndexingOrchestratorWorkflow x) => x.RunAsync(newInput));
}
}
So the idea is that we have a parent workflow (an orchestrator) that has, at any given time, a maximum amount of child workflows running simultaneously. When one of them finishes, it starts a new one and so forth.
Since this is a long-running workflow, we obviously need to support ContinueAsNew, which is fine. The problem is: how to I “transfer” the ongoing workflows to the next instance of the orchestrator workflow?
I can store the IDs, but the only thing I can do with them (I think) is to call GetExternalWorkflowHandle, but that handle doesn’t allow me to wait on them.
In other words: with a workflow ID, am I able to get the handle for said workflow from another workflow? If not, is what I’m doing incorrect?
Thank you in advance.