I am working with C# and .NET8. Azure Function Version 4 I have a Blob Trigger Azure Function running without issues in Azure cloud. The function is updated using GitHub Actions from my repository. When I want to add new features, I test them locally before deployment. The issue is that now, when I run the function locally, it starts triggering all the blob changes that have occurred since it was run locally. This usually takes a lot of time. When it finally finishes triggering, I run the new changes and it takes them hours to run.
Previously, it was just seconds. How can I reduce that delay in the trigger?
As @Mason A mentioned, if you are connecting to the same storage account which is being used in the deployed environment,
Blob Storage trigger with Azure Functions sometimes leads to delay in executions because the trigger polls the blob container for updates.
To reduce latency in these cases, trigger the function using an event subscription to the same container.
Refer the article.
I have tested the same in my environment by creating two containers in the same storage account and able to run the function without any delays.
Local Output:
Azure Functions Core Tools
Core Tools Version: 4.0.5611 Commit hash: N/A +591b8aec842e333a87ea9e23ba390bb5effe0655 (64-bit)
Function Runtime Version: 4.31.1.22191
[2024-04-05T12:45:41.720Z] Found C:\Users\uname\Source\Repos\FunctionApp.csproj. Using for user secrets file configuration.
[2024-04-05T12:46:14.567Z] Azure Functions .NET Worker (PID: 26804) initialized in debug mode. Waiting for debugger to attach...
[2024-04-05T12:46:14.791Z] Worker process started and initialized.
Functions:
Function1: blobTrigger
For detailed output, run func with --verbose flag.
[2024-04-05T12:46:19.651Z] Host lock lease acquired by instance ID '000000000000000000000000F72731CC'.
[2024-04-05T12:46:29.201Z] Executing 'Functions.Function1' (Reason='New blob detected(LogsAndContainerScan): samples-workitems/Hello World.txt', Id=881042fd-f65c-4254-841c-ceb6f414003e)
[2024-04-05T12:46:29.208Z] Trigger Details: MessageId: b377cda0-1de5-4524-8e14-ae735f4fa67b, DequeueCount: 1, InsertedOn: 2024-04-05T12:46:28.000+00:00, BlobCreated: 2024-04-05T12:46:24.000+00:00, BlobLastModified: 2024-04-05T12:46:24.000+00:00
[2024-04-05T12:46:31.849Z] C# Blob trigger function Processed blob
Name: Hello World.txt
Data: Hello World
[2024-04-05T12:46:31.921Z] Executed 'Functions.Function1' (Succeeded, Id=881042fd-f65c-4254-841c-ceb6f414003e, Duration=3164ms)