Priyanka Mane-Patil
Priyanka Mane-Patil

Reputation: 519

HTTP Trigger on demand azure function calling itself multiple times

I have added http triggered azure function and deployed it in function app. function app contains only one this http trigger on demand azure function. function app has app service plan, not consumption plan.

also, function app version is ~1. so that timeout is unlimited.

In the azure function code, I am reading one file having thousands of historical records and processing those records. this task is taking more than hour of time. this is one time task.

when I invoke this azure function after deployment, it gets invoked and after some time I noticed that it is getting invoked again and processing already processed records again.

Can anyone help me to understand invoking strategy of azure function, if azure function running for a long time without any status, will it callback itself?

if yes, how to stop this to call back again till it completes its processing.

Upvotes: 3

Views: 3977

Answers (1)

suziki
suziki

Reputation: 14080

Functions are supposed to be short-lived, they shouldn't run long time.The strength of Functions is in short-lived executions with small- or variable throughput.

Whenever possible, refactor large functions into smaller function sets that work together and return responses fast. For example, a webhook or HTTP trigger function might require an acknowledgment response within a certain time limit; it's common for webhooks to require an immediate response. You can pass the HTTP trigger payload into a queue to be processed by a queue trigger function. This approach lets you defer the actual work and return an immediate response.

Have a look of this:

https://learn.microsoft.com/en-us/azure/azure-functions/functions-best-practices#avoid-long-running-functions

With Durable Functions you can easily support long-running processes, applying the Async HTTP APIs. When in case you are dealing with functions that require some time to process the payload or request, running under an 'App Service Plan, WebJob, or Durable Functions' is the right way.

As suggested by @Thiago Custodio, you also need to split the large files into smaller ones, and pass them to activities in your durable functions workflow.

Upvotes: 3

Related Questions