Azure Web作业在超时后无法执行 [英] Azure web job failing to execute after timeout

查看:61
本文介绍了Azure Web作业在超时后无法执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一些连续运行的Web作业功能(随机)显示消息超时值00:30:00被功能'< myfunction>'超出(Id:< id>").开始取消.

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

谢谢.

解决方案

我的一些连续运行的Web作业功能(随机)显示消息超时值00:30:00被功能'< myfunction>'超出(Id:< id>").开始取消.

根据您的错误,我在

我建议您可以在函数中使用 CancellationToken 参数,并在发生超时或主机关闭时将其取消,并且可以按以下方式正常退出函数:

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.

after this message this function will not execute itself until and unless manually stop and start the azure web job.

Thanks in advance.

解决方案

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.

Based on your error, I found the related code from Microsoft.Azure.WebJobs.Host under FunctionExecutor.cs as follows:

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

I assumed that you specified the TimeoutAttribute for your function as follows:

I would recommend you could use a CancellationToken parameter in your function and it would be canceled whenever a timeout occurs or host shutdown, and you could exit your function gracefully as follows:

这篇关于Azure Web作业在超时后无法执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆