Home > OS >  Function in Azure stops running without explanation
Function in Azure stops running without explanation

Time:12-07

I have a program in Azure Functions, running in Python and triggered by an HTTP Trigger. This function processes and inserts into a database large Excel Files, superior to 10 thousand lines and around 10 columns. The process includes changing some things in the file and matching in the database, so it can take quite some time to run.

We currently have the Premium plan, which should not have any time execution limit, according to Microsoft documentation: https://docs.microsoft.com/en-us/azure/azure-functions/functions-scale However, after around one hour, the function simply stops working, without any error warning or problem. It simply stops, no explanation or error log of any kind, including the customized ones we created. The execution time is set for two hours right now, in this code:

"version": "2.0",
"extensionBundle": {
 "id": "Microsoft.Azure.Functions.ExtensionBundle",
 "version": "[2.*, 3.0.0)"
 },
"functionTimeout": "02:00:00" 

Since the function must return an HTTP status in a short limit of time, the long part from this process is executed in another thread.

t = threading.Thread(target=insertIntoDb, args=(data, fileName))
t.start()
return func.HttpResponse("File is currently being processed", status_code=202) 

Does anyone have an idea of what is happening or what can I check to solve this problem? Thank you.

CodePudding user response:

Even though you do the insert work on different thread, the main thread that did the http request processing may end and even the function host runtime may end after few minutes. For your use case, it is more preferable to receive the request and enter request details[not data] into a queue and do that long running work inside a durable function or in a queue trigger. Refer this, for handling long running logic in Azure - limits and guidance.

Even in Premium plan, the function execution is only guaranteed for 60 mins, not unbounded. Refer this MS doc

  • Related