Azure Web作业在超时后无法执行

时间:2017-08-07 09:07:50

标签: azure azure-webjobs

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

在此消息之后,除非手动停止并启动azure Web作业,否则此功能将不会自行执行。

提前致谢。

1 个答案:

答案 0 :(得分:0)

  

我的一些连续运行的Web作业功能(随机)显示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