Track each activity trigger outputs in durable functions

Viewed 45

I am trying to build an orchestrator service using durable function. It looks like this

public static class Flow
{
    [FunctionName(nameof(Flow))]
    public static async Task<List<string>> FlowRunOrchestrator(
        [OrchestrationTrigger]
        IDurableOrchestrationContext context)
    {
        var outputs = new List<string>();

        // Serial calls

        outputs.Add(await context.CallActivityAsync<string>(
            nameof(FlowSayHello), "Tokyo"));

        outputs.Add(await context.CallActivityAsync<string>(
            nameof(FlowSayHello), "Seattle"));

        outputs.Add(await context.CallActivityAsync<string>(nameof(
            FlowSayHello), "London"));

        return outputs;
    }

    [FunctionName(nameof(FlowSayHello))]
    public static async Task<string> FlowSayHello(
        [ActivityTrigger]
        string name,
        ILogger log)
    {
        await Task.Delay(10000);
        log.LogDebug($"Saying hello to {name}.");
        return $"Hello {name}!";
    }

    [FunctionName(nameof(FlowHttpStart))]
    public static async Task<HttpResponseMessage> FlowHttpStart(
        [HttpTrigger(
            AuthorizationLevel.Anonymous,
            "get",
            Route = "02")]
        HttpRequestMessage req,
        [DurableClient] IDurableOrchestrationClient starter,
        ILogger log)
    {
        string instanceId = await starter.StartNewAsync(nameof(Flow), null);

        log.LogInformation($"Started orchestration with ID = '{instanceId}'.");

        return starter.CreateCheckStatusResponse(req, instanceId);
    }
}

Here as you can see, every time the activity trigger being called it returns an output as well. So the output list getting updated by the activity trigger itsef.

But the challenge I am facing is I am not able to track the activity while the orchestration is Running. When I execute the status uri its retutrning the whole flow is completed or not. But I am not able to track which activity trigger is completed.

For example I am adding

outputs.Add(await context.CallActivityAsync<string>(
        nameof(FlowSayHello), "Tokyo"));

So it adds the output Hello Tokyo into the list. But when I run the status uri, the output list shows as null

{
    "name": "Flow",
    "instanceId": "dd8ed17a7fc4446fb9ee5e5087e53087",
    "runtimeStatus": "Running",
    "input": null,
    "customStatus": null,
    "output": null,
    "createdTime": "2022-07-12T14:54:22Z",
    "lastUpdatedTime": "2022-07-12T14:54:32Z"
}

But when all activity triggers finishes, it gives this

{
    "name": "Flow",
    "instanceId": "dd8ed17a7fc4446fb9ee5e5087e53087",
    "runtimeStatus": "Completed",
    "input": null,
    "customStatus": null,
    "output": [
        "Hello Tokyo!",
        "Hello Seattle!",
        "Hello London!"
    ],
    "createdTime": "2022-07-12T14:54:22Z",
    "lastUpdatedTime": "2022-07-12T14:54:53Z"
}

So I was expecting if Tokyo and and Seattle is completed it should show in the status uri response, but its not. So why we need to feed the list output as well.

So how can I achieve that?

0 Answers
Related