Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clearing history while debugging azure durable functions

Durable functions keep a state in storage, this is what makes them work, but it is very troublesome while debugging and developing. I have a large number of runs which have not completed and that the system tries to run again when I start the process. Some of the runs have erroneous data same which causes exceptions while others have been terminated early as something did not work as expected.

I don't want to run all the old cases when starting my application in debug (running against my local storage account). How can I automatically clear all data so only new functions will trigger?

like image 350
user1038502 Avatar asked Nov 23 '19 20:11

user1038502


People also ask

How to purge durable functions history in VS Code?

Type 'Purge Durable Functions History' in your Command Palette - and there you go. If you're not using VsCode, then the same tool is available as a standalone service, that you can either run locally or deploy into Azure. Show activity on this post.

How do I delete the history of a failed Azure instance?

The following command deletes the history of all failed instances created before November 14, 2021 at 7:35 PM (UTC). Using the func durable delete-task-hub command in Core Tools, you can delete all storage artifacts associated with a particular task hub, including Azure storage tables, queues, and blobs.

What makes a function durable in azure?

Durable Functions are durable because they keep their state in a data store, Azure Storage usually. This does mean that over time you might start having a lot of data there. Especially if those orchestrations are executed often and/or run many operations. Storing that data costs something, though Table Storage is pretty cheap.

How do I remove orchestration instance history in durable functions?

In this article I'll show you some approaches for removing orchestration instance history in Durable Functions. The most performant way of cleaning up instance history is to target a specific orchestration instance. If you have stored the instance ids in a database, this can be a really good way.


3 Answers

You can use Azure Core Tools to purge the orchestration instance state.

First you need to make sure that the Azure Core Tools is installed for your particular Azure Function version. You can do this using the NPM package manager. (Note that this is for the Azure Functions Version - V3.)

npm install -g azure-functions-core-tools@3

Then open a command prompt in the root directory of your Azure Functions project. The Azure Core Tools requires the host.json file from your project to identify your orchestration instances.

You can use the following to look at all of the available actions:

func durable 

You can then purge the instance history using the following:

func durable purge-history
like image 164
sirius90 Avatar answered Oct 22 '22 22:10

sirius90


There is now this VsCode extension, which now also has 'Purge Durable Functions History' feature. Type 'Purge Durable Functions History' in your Command Palette - and there you go. If you're not using VsCode, then the same tool is available as a standalone service, that you can either run locally or deploy into Azure.

like image 32
scale_tone Avatar answered Oct 22 '22 23:10

scale_tone


You may call the PurgeInstanceHistoryAsync method with one of the following:

  1. An orchestration instance ID
[FunctionName("PurgeInstanceHistory")]
public static Task Run(
    [DurableClient] IDurableOrchestrationClient client,
    [ManualTrigger] string instanceId)
{
    return client.PurgeInstanceHistoryAsync(instanceId);
}
  1. Time interval
[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
        });
}

Reference for code snippets above: https://learn.microsoft.com/en-gb/azure/azure-functions/durable/durable-functions-instance-management#purge-instance-history

like image 43
Ling Toh Avatar answered Oct 22 '22 23:10

Ling Toh