Issue getting data back to webhook URL when using Azure Durable Function.

Marc Hedgley 185 Reputation points
2024-01-25T13:42:11.6666667+00:00

Hello, We are calling Azure Durable function from Azure Logic App - from Http Webhook action and we have noticed that the Webhook action is notified the status from Durable function such as – Running , Succeeded  etc which is originally from Orchestrator function but we are unable to get the actual data which we are posting back  to the Webhook URL.   The Azure function(FormatScanOrchestrator_HttpStart) is called from Logic app - Http Webhook action is based on HttpTrigger and which internally call Azure Orchestrator function(FormatScanOrchestrator)  and the Orchestartor function is executing  a FormatScan function - which is a long running function – unzip large datasets of 20GB size from Azure storage and scan all file formats. The durable function is running for a long duration and returning data – which can be seen from Monitor and logs but it is failing to post data back to the web hook url .    We are using the following code to POST the data to Webhook url and there are no exception or error in logs but we are unable to post the data to Logic app action. I am requesting for any advice or guidance on how we can get the data back to the web hook URL?

Please find the logic app HttpWebhook action details as below

 

The following attached is the high level code of Azure Durable functions

  [FunctionName("FormatScanOrchestrator_HttpStart")]
        public static async Task<HttpResponseMessage> HttpStart(
                   [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post"),] HttpRequestMessage req,
                   [DurableClient] IDurableOrchestrationClient starter,
                   ILogger log)
        {
            string instanceId = await starter.StartNewAsync("FormatScanOrchestrator", null, jsonContent);
            HttpClient client = new HttpClient();
            var status = await starter.GetStatusAsync(instanceId);

            if (status.RuntimeStatus.ToString() == "Completed")
            {
                await client.PostAsync(callBackUrl.ToString(),
                status.output, new JsonMediaTypeFormatter(), "application/json");
            }

        }
        return await starter.WaitForCompletionOrCreateCheckStatusResponseAsync(req, instanceId);
    }
    [FunctionName("FormatScanOrchestrator")]
    
    public static async Task<ObjectResult> RunOrchestrator(
                [OrchestrationTrigger] IDurableOrchestrationContext context)
    {

        string input = context.GetInput<string>();

        return await context.CallActivityAsync<ObjectResult>(nameof(FormatScan), input);

    }


    [FunctionName(nameof(FormatScan))]
    public static async Task<ObjectResult> FormatScan([ActivityTrigger] string jsonInput, ILogger log)
    {
        if (!isContentNonWhiteListed)
        {
             return new OkObjectResult(files);
        }
        return new ObjectResult("nonwhitelistformatfound");
    }

          await client.PostAsync(callBackUrl.ToString(),
             status.output, new JsonMediaTypeFormatter(), "application/json");

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
{count} votes

Accepted answer
  1. MuthuKumaranMurugaachari-MSFT 22,441 Reputation points Moderator
    2024-02-01T16:44:09.94+00:00

    Marc Hedgley Thanks for posting your question in Microsoft Q&A. From the code snippet above, you are calling GetStatusAsync API to get the status of the orchestration instance. However, immediately after creating StartNewAsync will just get the status of the orchestration which may not be completed in case of long running status (refer Query instances).

    Usually, you can run it in while loop to check the status periodically as in the sample https://github.com/Azure/azure-functions-durable-extension/blob/dev/samples/functionapp-csharp/ClientFunction.cs or call WaitForCompletionOrCreateCheckStatusResponseAsync to wait for orchestration completion as described in Wait for orchestration completion and then call the webhook URL to post the data.

    Note: the default timeout value is 10 seconds and increase the value as needed instead of running it forever.

    I hope this helps and let me know if you have any questions.


    If you found the answer to your question helpful, please take a moment to mark it as Yes for others to benefit from your experience. Or simply add a comment tagging me and would be happy to answer your questions.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.