Search code examples
azureazure-functionsazure-functions-core-tools

Azure Functions Core Tools - hidden triggers or caching?


I'm developing simple azure function with Visual Studio 2019. I'm using Azure Functions Core Tools as they are started every time I start my project.

The functions are time triggered and activity triggered. Every time I start my project again, the Azure Functions Core Tools starts too - and now the wired is happening:

It looks like the functions are not only called once from the current runtime as expected - but also from old triggers, running still in the background. If stop in one of the functions, it sometimes gets "old" data from runs of my projects before. I'm also getting warnings about unknown functions, I renamed in my projects dozen runs before.

I cleared the /bin/ path of my project - but old functions seems to be alive in something like a hidden cache or a hidden runtime of the Azure Functions Core Tools.

Is there a master stop or a master cleanup I can run before every new start of my project in the Azure Functions Core Tools?

And can it be, that this behavior also happens in the real Azure environment - since I see time triggered functions there running in faster cycles as they should ran - maybe triggered by still running timers from published instances before?


Solution

  • If you're using Durable Framework (based on your previous question), you need to delete the storage artifacts otherwise, it will execute previous non completed executions.

    There are a few ways to do that:

    [FunctionName("PurgeInstanceHistory")]
    public static Task Run(
        [DurableClient] IDurableOrchestrationClient client,
        [TimerTrigger("0 0 12 * * *")]TimerInfo myTimer)
    {
        return client.PurgeInstanceHistoryAsync(
            DateTime.MinValue,
            DateTime.UtcNow.AddDays(-30),  
            new List<OrchestrationStatus>
            {
                OrchestrationStatus.Completed
            });
    }
    

    you can also use CLI for it:

    func durable delete-task-hub --task-hub-name UserTest
    

    as another option, you can manually delete the artifacts using Microsoft Azure Storage Explorer and connecting it to local storage emulator:

    enter image description here