2

I'm creating an Azure Function to process files. The Azure Function will be activated with a HTTP Trigger, so the function should be executed whenever a page from a site makes a HTTP request to it.

The Function will take some time to finish processing the files, but I can't get the site waiting for the Function to finish to know If everything was ok. So what I want is some kind of "received" message from the Azure Function just to know that it received the HTTP request, before it starts processing.

Is there any way to do that with a HTTP Trigger? Can I let the caller know that its request was correctly received and, after that, start executing the Azure Function?

1 Answer 1

3

Yes, it's super easy to do that using Durable Functions:

1- Install 'Microsoft.Azure.WebJobs.Extensions.DurableTask' nuget package;

2-

   [FunctionName("Function1")]
    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
        [DurableClient] IDurableOrchestrationClient starter,
        ILogger log)
    {
        Guid instanceId = Guid.NewGuid();
        string x = await starter.StartNewAsync("Processor", instanceId.ToString(), null);

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

        return starter.CreateCheckStatusResponse(req, x);
    }

3-

    [FunctionName("Processor")]
    public static async Task<string> Search([OrchestrationTrigger] IDurableOrchestrationContext context)
    {
        var output= await context.CallActivityAsync<string>("DoSomething", null);

        return output;
    }



   [FunctionName("DoSomething")]
    public static async Task<string> Execute([ActivityTrigger] string termo, ILogger log)
    {
        //do your work in here
    }

In the previous code we're creating an Orchestrator (Processor) function, and it will start an activity which will do the process DoSomething function.

More info: https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-overview

Sign up to request clarification or add additional context in comments.

1 Comment

PS: The first function will give you an endpoint that you can check if the process is completed or not

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.