Azure Durable Function 运行 可以使用多长时间?

How long can an Azure Durable Function run for?

我有多个 ETL 类型的任务,我计划执行无服务器。任务的执行时间从 5 到 30 分钟不等(取决于来自实例的数据量)。由于函数有 10 分钟的超时时间,因此无法在一个函数中同时执行这些任务。我最近在 Azure 中遇到了 Durable Functions,用于编排不同的功能。我想知道持久函数是否也有 10 分钟的超时,或者我可以在其中包含多个函数(每个函数 运行 从 3-5 分钟开始)。

例如,任务 1 需要 3 分钟,任务 2 需要 5 分钟,任务 3 需要 7 分钟,任务 4 需要 3 分钟,任务 5 需要 2 分钟。我可以将所有这些任务编排在一个持久的函数中吗?

我目前的做法是为每个任务单独设置一个队列触发功能,但是这样的工作流程很安静很乱。我觉得持久的功能最适合简化工作流程。

Can I have all these tasks orchestrated in a single durable function?

简而言之:是的。但这里有一些上下文。

Durable Functions is an extension of Azure Functions that lets you write stateful functions in a serverless compute environment. The extension lets you define stateful workflows by writing orchestrator functions and stateful entities by writing entity functions using the Azure Functions programming model. Behind the scenes, the extension manages state, checkpoints, and restarts for you, allowing you to focus on your business logic.

听起来您的方案最适合函数链接模式。

Function chaining

In the function chaining pattern, a sequence of functions executes in a specific order. In this pattern, the output of one function is applied to the input of another function.

这方面的代码比较简单:

[FunctionName("Chaining")]
public static async Task<object> Run(
    [OrchestrationTrigger] IDurableOrchestrationContext context)
{
    try
    {
        var x = await context.CallActivityAsync<object>("F1", null);
        var y = await context.CallActivityAsync<object>("F2", x);
        var z = await context.CallActivityAsync<object>("F3", y);
        return  await context.CallActivityAsync<object>("F4", z);
    }
    catch (Exception)
    {
        // Error handling or compensation goes here.
    }
}

此示例中的每个单独的功能(F1 到 F4)都是它自己的功能。这意味着它有自己的超时时间。

请注意,不同类型的托管计划可能更适合您的问题。查看 Azure Functions hosting options - Service limits 了解选项及其各自的(超时)限制。