连续 WebJob stopping_wait_time 被忽略?
Continuous WebJob stopping_wait_time ignored?
经过昨天的提问 () 我想现在我已经理解了连续 WebJobs 和正常关闭的处理并做了一些测试。
附加信息
使用 https://myWebJob.scm.azurewebsites.net/api/continuouswebjobs
我得到:
{
[some info ommited...]
"type": "continuous",
"error": null,
"using_sdk": true,
"settings": {
"stopping_wait_time": 120
}
}
2015 年 12 月 31 日星期四 07:00:23 GMT 我停止了服务器,仪表板中的以下条目是:
[12/31/2015 07:00:23 > d71f29: SYS INFO] Status changed to Disabling
[12/31/2015 07:00:28 > d71f29: SYS INFO] Detected WebJob file/s were updated, refreshing WebJob
[12/31/2015 07:00:28 > d71f29: SYS INFO] Status changed to Stopping
[12/31/2015 07:00:30 > d71f29: INFO] Job host stopped
[12/31/2015 07:00:32 > d71f29: SYS INFO] Status changed to Success
[12/31/2015 07:00:32 > d71f29: SYS INFO] Status changed to Stopped
我的 运行 工作立即结束,没有任何进一步的信息。
我函数的最后两行代码是记录到仪表板并将条目写入存储 table。 None 这些条目已写入...我重试了几次,每次都在 5 秒内作业主机停止。所以:
问题
对于连续的 WebJobs,"stopping_wait_time" 值是否被优雅地忽略了?
你完全正确。对于连续的 WebJobs,参数 stopping_wait_time" 值将被忽略。
对于连续的 WebJobs Azure 将在 WebJob 运行 进程即将停止时通知它,然后它将等待一段可配置的时间(默认情况下为 5 秒),之后如果该进程没有安静地退出它会关闭它
对于触发的 WebJobs(而不是连续的 WebJobs),没有关闭通知,但有一个宽限期(默认为 30 秒),WebJob 不会立即强制关闭,宽限期是可配置的。
这里有完整的解释。
http://blog.amitapple.com/post/2014/05/webjobs-graceful-shutdown/#.VM9Su40tEic
希望对您有所帮助
最好的祝福
斯蒂芬
stopping_wait_time
设置被连续作业和触发作业使用。您可以看到连续作业 运行ner 如何使用此设置 here in the source code。
我上传了一个 工作示例 演示正常关机 here。在该示例中,我将关闭超时设置为 60 秒,并验证我的工作函数能够执行 30 秒的关闭 activity w/o 被杀死。
请下载该示例并试用。您还可以 运行 本地示例,如上面链接的示例自述文件中所述。我还在此处内联了示例函数,展示了如何使用 CancellationToken:
public static class Functions
{
[NoAutomaticTrigger]
public static async Task GracefulShutdown(CancellationToken cancellationToken)
{
// Simulate a long running function, passing in the CancellationToken to
// all async operations we initiate.
// We can also monitor CancellationToken.IsCancellationRequested in our code
// if our code is iterative.
try
{
await Task.Delay(TimeSpan.FromMinutes(10), cancellationToken);
}
catch (TaskCanceledException)
{
Shutdown().Wait();
}
Console.WriteLine("Function completed succesfully.");
}
private static async Task Shutdown()
{
// simulate some cleanup work to show that the Continuous job host
// will wait for the time configured via stopping_wait_time before
// killing the process. The default value for stopping_wait_time is 5 seconds,
// so this code will demonstrate that our override in settings.job
// is functional.
Console.WriteLine("Function has been cancelled. Performing cleanup ...");
await Task.Delay(TimeSpan.FromSeconds(30));
Console.WriteLine("Function was cancelled and has terminated gracefully.");
}
此函数的 30 秒正常关机逻辑 运行s 成功,如控制台输出所示:
- [12/31/2015 17:15:08 > 951460: SYS INFO] 状态更改为停止
- [12/31/2015 17:15:09 > 951460: INFO] 功能已被取消。正在执行清理...
- [12/31/2015 17:15:39 > 951460: INFO] 函数已取消并正常终止。
- [12/31/2015 17:15:39 > 951460: INFO] 功能已成功完成。
- [12/31/2015 17:15:39 > 951460: INFO] 作业主机已停止
- [12/31/2015 17:15:39 > 951460: SYS INFO] 状态更改为成功
- [12/31/2015 17:15:39 > 951460: SYS INFO] 状态更改为已停止
编辑 2019 年 3 月 19 日
可根据文档配置设置,方法是在 settings.job
中设置 stopping_wait_time
值。在幕后,JobSettings.GetStoppingWaitTime
方法将根据该设置检索 TimeSpan
或 5 秒的默认值(当设置中不存在时)。
public TimeSpan GetStoppingWaitTime(long defaultTime)
{
return TimeSpan.FromSeconds(GetSetting(JobSettingsKeys.StoppingWaitTime, defaultTime));
}
我错了,我不应该剪切和粘贴。我想说的(如果我的理解是正确的)是你不能配置这个默认时间 - 如果你在这里阅读 https://github.com/projectkudu/kudu/wiki/Web-jobs 没有提到 "configurable" 并且它是目前在 Kudu 服务如果您在 Kudu.core.
的 ContinuousJobRunner.cs 文件中的 GitHub 上获取代码
5 是默认的硬编码值
public class ContinuousJobRunner : BaseJobRunner, IDisposable
{
public const string WebsiteSCMAlwaysOnEnabledKey = "WEBSITE_SCM_ALWAYS_ON_ENABLED";
private const int DefaultContinuousJobStoppingWaitTimeInSeconds = 5;
private static readonly TimeSpan WarmupTimeSpan = TimeSpan.FromMinutes(2);
....
_continuousJobLogger.ReportStatus(ContinuousJobStatus.Stopping);
NotifyShutdownJob();
// By default give the continuous job 5 seconds before killing it (after notifying the continuous job)
if (!_continuousJobThread.Join(JobSettings.GetStoppingWaitTime(DefaultContinuousJobStoppingWaitTimeInSeconds)))
{
_continuousJobThread.Abort();
}
_continuousJobThread = null;
希望对您有所帮助
新年快乐
斯蒂芬
经过昨天的提问 (
附加信息
使用 https://myWebJob.scm.azurewebsites.net/api/continuouswebjobs
我得到:
{
[some info ommited...]
"type": "continuous",
"error": null,
"using_sdk": true,
"settings": {
"stopping_wait_time": 120
}
}
2015 年 12 月 31 日星期四 07:00:23 GMT 我停止了服务器,仪表板中的以下条目是:
[12/31/2015 07:00:23 > d71f29: SYS INFO] Status changed to Disabling [12/31/2015 07:00:28 > d71f29: SYS INFO] Detected WebJob file/s were updated, refreshing WebJob [12/31/2015 07:00:28 > d71f29: SYS INFO] Status changed to Stopping [12/31/2015 07:00:30 > d71f29: INFO] Job host stopped [12/31/2015 07:00:32 > d71f29: SYS INFO] Status changed to Success [12/31/2015 07:00:32 > d71f29: SYS INFO] Status changed to Stopped
我的 运行 工作立即结束,没有任何进一步的信息。 我函数的最后两行代码是记录到仪表板并将条目写入存储 table。 None 这些条目已写入...我重试了几次,每次都在 5 秒内作业主机停止。所以:
问题
对于连续的 WebJobs,"stopping_wait_time" 值是否被优雅地忽略了?
你完全正确。对于连续的 WebJobs,参数 stopping_wait_time" 值将被忽略。
对于连续的 WebJobs Azure 将在 WebJob 运行 进程即将停止时通知它,然后它将等待一段可配置的时间(默认情况下为 5 秒),之后如果该进程没有安静地退出它会关闭它
对于触发的 WebJobs(而不是连续的 WebJobs),没有关闭通知,但有一个宽限期(默认为 30 秒),WebJob 不会立即强制关闭,宽限期是可配置的。
这里有完整的解释。 http://blog.amitapple.com/post/2014/05/webjobs-graceful-shutdown/#.VM9Su40tEic
希望对您有所帮助 最好的祝福 斯蒂芬
stopping_wait_time
设置被连续作业和触发作业使用。您可以看到连续作业 运行ner 如何使用此设置 here in the source code。
我上传了一个 工作示例 演示正常关机 here。在该示例中,我将关闭超时设置为 60 秒,并验证我的工作函数能够执行 30 秒的关闭 activity w/o 被杀死。
请下载该示例并试用。您还可以 运行 本地示例,如上面链接的示例自述文件中所述。我还在此处内联了示例函数,展示了如何使用 CancellationToken:
public static class Functions
{
[NoAutomaticTrigger]
public static async Task GracefulShutdown(CancellationToken cancellationToken)
{
// Simulate a long running function, passing in the CancellationToken to
// all async operations we initiate.
// We can also monitor CancellationToken.IsCancellationRequested in our code
// if our code is iterative.
try
{
await Task.Delay(TimeSpan.FromMinutes(10), cancellationToken);
}
catch (TaskCanceledException)
{
Shutdown().Wait();
}
Console.WriteLine("Function completed succesfully.");
}
private static async Task Shutdown()
{
// simulate some cleanup work to show that the Continuous job host
// will wait for the time configured via stopping_wait_time before
// killing the process. The default value for stopping_wait_time is 5 seconds,
// so this code will demonstrate that our override in settings.job
// is functional.
Console.WriteLine("Function has been cancelled. Performing cleanup ...");
await Task.Delay(TimeSpan.FromSeconds(30));
Console.WriteLine("Function was cancelled and has terminated gracefully.");
}
此函数的 30 秒正常关机逻辑 运行s 成功,如控制台输出所示:
- [12/31/2015 17:15:08 > 951460: SYS INFO] 状态更改为停止
- [12/31/2015 17:15:09 > 951460: INFO] 功能已被取消。正在执行清理...
- [12/31/2015 17:15:39 > 951460: INFO] 函数已取消并正常终止。
- [12/31/2015 17:15:39 > 951460: INFO] 功能已成功完成。
- [12/31/2015 17:15:39 > 951460: INFO] 作业主机已停止
- [12/31/2015 17:15:39 > 951460: SYS INFO] 状态更改为成功
- [12/31/2015 17:15:39 > 951460: SYS INFO] 状态更改为已停止
编辑 2019 年 3 月 19 日
可根据文档配置设置,方法是在 settings.job
中设置 stopping_wait_time
值。在幕后,JobSettings.GetStoppingWaitTime
方法将根据该设置检索 TimeSpan
或 5 秒的默认值(当设置中不存在时)。
public TimeSpan GetStoppingWaitTime(long defaultTime)
{
return TimeSpan.FromSeconds(GetSetting(JobSettingsKeys.StoppingWaitTime, defaultTime));
}
我错了,我不应该剪切和粘贴。我想说的(如果我的理解是正确的)是你不能配置这个默认时间 - 如果你在这里阅读 https://github.com/projectkudu/kudu/wiki/Web-jobs 没有提到 "configurable" 并且它是目前在 Kudu 服务如果您在 Kudu.core.
的 ContinuousJobRunner.cs 文件中的 GitHub 上获取代码5 是默认的硬编码值
public class ContinuousJobRunner : BaseJobRunner, IDisposable
{
public const string WebsiteSCMAlwaysOnEnabledKey = "WEBSITE_SCM_ALWAYS_ON_ENABLED";
private const int DefaultContinuousJobStoppingWaitTimeInSeconds = 5;
private static readonly TimeSpan WarmupTimeSpan = TimeSpan.FromMinutes(2);
....
_continuousJobLogger.ReportStatus(ContinuousJobStatus.Stopping);
NotifyShutdownJob();
// By default give the continuous job 5 seconds before killing it (after notifying the continuous job)
if (!_continuousJobThread.Join(JobSettings.GetStoppingWaitTime(DefaultContinuousJobStoppingWaitTimeInSeconds)))
{
_continuousJobThread.Abort();
}
_continuousJobThread = null;
希望对您有所帮助 新年快乐 斯蒂芬