gpt4 book ai didi

c# - Azure Web 作业正常关闭

转载 作者:行者123 更新时间:2023-12-03 03:11:47 25 4
gpt4 key购买 nike

我正在尝试为连续的 Azure Web 作业实现正常关闭,前提是提供所需的作业设置:

{
"stopping_wait_time": 3600,
"is_singleton": true
}

我已经注册了回调:

    static void Main(string[] args)
{

var cancellationToken = new WebJobsShutdownWatcher().Token;
cancellationToken.Register(() =>
{

Console.WriteLine("Shutdown Started...");

Thread.Sleep(5000);
Console.WriteLine("Waited 5 seconds!" + DateTime.Now.ToString());
Thread.Sleep(5000);
Console.WriteLine("Waited 10 seconds!" + DateTime.Now.ToString());
Thread.Sleep(5000);
Console.WriteLine("Waited 15 seconds!" + DateTime.Now.ToString());
Thread.Sleep(5000);
Console.WriteLine("Waited 20 seconds!" + DateTime.Now.ToString());
Thread.Sleep(5000);
Console.WriteLine("Waited 25 seconds!" + DateTime.Now.ToString());
Thread.Sleep(5000);
Console.WriteLine("Waited 30 seconds!" + DateTime.Now.ToString());

});


JobHost host = new JobHost();

MethodInfo methodInfo = typeof(Functions).GetMethod("GracefulShutdown");
host.CallAsync(methodInfo); //a long running method
host.RunAndBlock();
}

但是在停止网络作业时,我永远无法执行回调的最后一行:

Console.WriteLine("Waited 30 seconds!" + DateTime.Now.ToString()

有什么想法吗?

最佳答案

For triggered WebJobs there is no shutdown notification but there is a graceful period (30 seconds by default) where the WebJob will not be forcefully shutdown immediately, the graceful period is configurable.

The graceful period can be updated for any WebJob, the way to do it is to create a file called settings.job with the following content: { "stopping_wait_time": 60 }

我可以看到您的宽限期仍然是 30 秒,与默认值相同。请检查您的settings.job是否放在正确的位置。您将其放在 webjob 可执行文件所在的同一目录中(我假设您通过门户上传了一个 zip 文件?如果是这样,只需将设置文件放在您正在使用的 .exe 或 .cmd 旁边的 zip 中)。

参见http://blog.amitapple.com/post/2014/05/webjobs-graceful-shutdown/#.Vw3HdUcl_dV了解更多详情。

关于c# - Azure Web 作业正常关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36571553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com