0

I have an external API which invokes my HTTP trigger azure function with the same query parameters 5 times at the same moment. So 5 requests are processed in the same time concurrently, each request adds a record to my google sheet and it causes unwanted duplicated records. My function is checking for duplicate in that sheet before pushing new record but when 5 instances are called a the same time concurrently, duplicate does not exist. Is there any simple solution to achieve processing those 5 request one by one, without concurrency?

Hawos
  • 33
  • 6

1 Answers1

0

I have same trouble here but with CosmosDB. If I make x times same request at same time on Azure Function it just query for a property in Cosmos, but it already doesn't exists and duplicate the insertion but with different ID.

I'm looking for a solution, but the best I anchieved until now is to use [Singleton] decorator on .Net environment. It makes the function finish a request before start another one.

[Singleton]
public async Task<IActionResult> FunctionName(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "functionRoute")] HttpRequest req)
{
    //your code here
}

If anyone have another solution, please post here.

Some more information about my duplicated data:

  • They have the same _ts (timestamp) on Cosmos;
  • Watching to a Date propertie from the created objects, the difference between they are about milliseconds;
  • Watching to ApplicationInsigths the function Excuted message are at the same time hh:mm:ss;

Edit:

Today I found that: https://learn.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#scope-values

and make something like this:

[Singleton("{anyParameter}")]
[OpenApiParameter(name: "anyParameter", In = ParameterLocation.Query, Required = true, Type = typeof(string), Description = "anyParameter")]
public async Task<IActionResult> FunctionName(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "functionRoute")] HttpRequest req)
{
    //your code here
}

It worked to me. If there is a Function instance running with same "anyParameter" parameter it executes like an queue. If the parameters are different it create another instace and run on another Function Instance;

Watching to Application Insights it shows that requisitions with the same "anyParameter" execute like in queue, and duration time of function Increase for every request. But with another value to "anyParameter" it really creates another instance and the requisitions are being completed at the same speed time.