我的一些连续运行的网络作业功能(随机)显示消息 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
对于您的功能如下:
我建议您可以使用CancellationToken
参数在你的函数中,每当发生超时或主机关闭时,它就会被取消,你可以优雅地退出你的函数,如下所示:
关于Azure Web 作业超时后无法执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45543191/