Infarch
Infarch

Reputation: 71

Http trigger in Azure functions application

I have an Azure functions application performing background jobs for my web site. Some jobs are started on demand. To achieve that I use a single HTTP trigger function calling it from web server, providing job details. The function starts a corresponding orchestration and returns a check status response.

In simplified form, that launcher function looks like this:

[FunctionName(nameof(StartJob))]
public async Task<HttpResponseMessage> StartJob(
    [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req,
    [DurableClient] IDurableOrchestrationClient starter,
    ILogger log)
{
    HttpContent? content = req.Content ?? throw new Exception("Request body missing");
    string requestBody = await content.ReadAsStringAsync();

    dynamic jObject = JsonConvert.DeserializeObject(requestBody) ?? throw new Exception("No data");

    int requestId = (int)jObject.RequestId;

    // read the task description from DB
    var task = await ServerTaskHelper.GetTaskAsync(_connectionHelper, requestId);

    // start executing
    var oid = await starter.StartNewAsync(task.OrchestratorFunction);
    return starter.CreateCheckStatusResponse(req, oid);
}

It works well in test environment, but in production, some requests fail. Unfortunately I do not know the response code: there is no appropriate logging for now. But I think it could be due to big number of requests.

My question: is it a good approach to start jobs on demand? How many requests can an Azure Function app handle? Maybe it is better to put requests into a queue on the web server, and make a queue trigger in Azure?

The runtime version of my Azure application is 4.28.4.4 targeting .NET 6.0, with "in-process" model. Pricing plan is "Premium v3 P1V3".

Thank you in advance!

Upvotes: 0

Views: 765

Answers (1)

Arunprasath
Arunprasath

Reputation: 331

In certain situation it is true the by demand is a right approach by demand. If the volume is high and need an 100 % transaction success, then a queue is better approach.

Also, you are using Durable function, so there will be a storage account which store the state of the function, I request you review those tables you may identify the issue.

Also verify if the Azure function always on is turned on Azure function (How do I turn on "always-on" for an Azure Function?)

Upvotes: 0

Related Questions