Azure 持久函数和数据保留

Azure durable functions and retention of data

我可以看到 azure durable functions 使用存储帐户来管理状态和检测。当运行持久函数在数据表和队列量大的环境下会越来越大,适当的越来越慢。 durable function clean 是否自行记录它们,或者这是您需要自己完成的任务?

编排历史将在编排完成、失败或终止后的一些天数(例如 30 天)内被删除。删除此数据后,将无法再查询已清除实例的状态。天数可在任务中心级别配置,清理将由运行时自动完成

更多详细信息,请参阅此github issue

对此进行研究后,开发人员似乎需要为此实现自己的处理程序。我通读了 github 发布的已接受答案,看起来功能团队只实现了 API 所需的 but no automated code.

Here's the example from the official docs - 只是添加了一个计时器功能,可以删除最多 30 天前的所有历史记录。

[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 });
}

他们还在文档中指出清除大量记录可能……很慢。他们不是在开玩笑。您可以在使用 HTTP API call 将其自动化之前赶上清除。

DELETE /runtime/webhooks/durabletask/instances
    ?taskHub={taskHub}
    &connection={connectionName}
    &code={systemKey}
    &createdTimeFrom={timestamp}
    &createdTimeTo={timestamp}
    &runtimeStatus={runtimeStatus1,runtimeStatus2,...}