Azure Web 作业超时后无法执行

标签 azure azure-webjobs

我的一些连续运行的网络作业功能(随机)显示消息 Timeout value of 00:30:00 exceeded by function '<myfunction>' (Id: '<id>'). Initiating cancellation .

在此消息之后,除非手动停止并启动 Azure Web 作业,否则该函数不会自行执行。

提前致谢。

最佳答案

some of my continuous running web job function(random) show message of Timeout value of 00:30:00 exceeded by function '<myfunction>' (Id: '<id>'). Initiating cancellation.

根据您的错误,我在FunctionExecutor.cs下从Microsoft.Azure.WebJobs.Host找到了相关代码如下:

internal static void OnFunctionTimeout(System.Timers.Timer timer, FunctionDescriptor method, Guid instanceId, TimeSpan timeout, bool timeoutWhileDebugging,
    TraceWriter trace, ILogger logger, CancellationTokenSource cancellationTokenSource, Func<bool> isDebuggerAttached)
{
    timer.Stop();

    bool shouldTimeout = timeoutWhileDebugging || !isDebuggerAttached();
    string message = string.Format(CultureInfo.InvariantCulture,
        "Timeout value of {0} exceeded by function '{1}' (Id: '{2}'). {3}",
        timeout.ToString(), method.ShortName, instanceId,
        shouldTimeout ? "Initiating cancellation." : "Function will not be cancelled while debugging.");

    trace.Error(message, null, TraceSource.Execution);
    logger?.LogError(message);

    trace.Flush();

    // Only cancel the token if not debugging
    if (shouldTimeout)
    {
        // only cancel the token AFTER we've logged our error, since
        // the Dashboard function output is also tied to this cancellation
        // token and we don't want to dispose the logger prematurely.
        cancellationTokenSource.Cancel();
    }
}

我假设您指定了 TimeoutAttribute对于您的功能如下:

enter image description here

我建议您可以使用CancellationToken参数在你的函数中,每当发生超时或主机关闭时,它就会被取消,你可以优雅地退出你的函数,如下所示:

enter image description here

关于Azure Web 作业超时后无法执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45543191/

相关文章:

c# - 如何在本地运行 Azure WebJob?

azure - 两个 Azure 移动服务(.NET 后端)共享同一数据库

azure - 什么是 Docker 注册表服务连接?

visual-studio-2013 - 'DefaultConnection-Web.config Connection String' 参数不能为 null 或为空

c# - 如何将无触发的.NET Core控制台应用程序实现为连续的Azure WebJob?

c# - Webjob 未使用正确的配置发布

Azure WebJob 不传递参数

azure - 使用 Python SDK 生成 Azure 容器 SAS token 时出错

azure - Web 应用服务 - 应多久重新启动一次?

.net - 为什么我得到 "An error occured while processing your request"?