消耗计划的 Azure Functions 超时

Azure Functions timeout for Consumption plan

有没有办法更改消费计划下 Azure Functions 运行 当前的 5 分钟超时限制?

对于某些数据分析计算,5 分钟是不够的。

使用 webjobs 的替代方法不允许并行执行函数。

Azure Functions 现在可以 运行 使用消耗计划最多 10 分钟: https://docs.microsoft.com/en-us/azure/azure-functions/functions-host-json#functiontimeout

(其他答案有点乱,所以写了很多而不是编辑)

Azure Functions 现在可以 运行 通过将 functionTimeout 设置添加到您的 host.json 文件来使用消耗计划最多 10 分钟:

In a serverless Consumption plan, the valid range is from 1 second to 10 minutes, and the default value is 5 minutes.

In both Premium and Dedicated (App Service) plans, there is no overall limit, and the default value is 30 minutes. A value of -1 indicates unbounded execution, but keeping a fixed upper bound is recommended

来源:https://docs.microsoft.com/en-us/azure/azure-functions/functions-host-json#functiontimeout

文件:host.json

// Value indicating the timeout duration for all functions.
// Set functionTimeout to 10 minutes
{
    "functionTimeout": "00:10:00"
}

来源:
https://buildazure.com/2017/08/17/azure-functions-extend-execution-timeout-past-5-minutes/
https://github.com/Azure/azure-webjobs-sdk-script/wiki/host.json

这里是完整的host.json,重述到Microsoft Docs:

不要忘记重启函数以重新加载配置!

{
   "version":"2.0",
   "managedDependency":{
      "Enabled":true
   },
   "extensionBundle":{
      "id":"Microsoft.Azure.Functions.ExtensionBundle",
      "version":"[2.*, 3.0.0)"
   },
   "functionTimeout": "00:05:00"
}

另一个技巧是,只在 requirements.psd1 中定义所需的 Az-Modules 而不是全部:

差:

# This file enables modules to be automatically managed by the Functions service.
# See https://aka.ms/functionsmanageddependency for additional information.
#
@{
    # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. 
    # To use the Az module in your function app, please uncomment the line below.
    'Az' = '6.*'
}

好:

# This file enables modules to be automatically managed by the Functions service.
# See https://aka.ms/functionsmanageddependency for additional information.
#
@{
    # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. 
    # To use the Az module in your function app, please uncomment the line below.
    # 'Az' = '6.*'
    'Az.Accounts'  = '2.*'
    'Az.Resources' = '4.*'
    'Az.Monitor'   = '2.*'
}