Azure Webjob在0秒后重新启动。为什么?

时间:2018-11-30 11:33:20

标签: c# azure error-handling azure-webjobs

我的webjob是一项连续的工作,就像它应该循环播放一样,这样它就不会停止运行。我有一个小的错误处理程序,它将重新启动作业5次,直到它在代码中停用了作业本身。很好。

但是,如果它是第一次重新启动,则将WEBJOBS_RESTART_TIME设置为0或以下示例中的其他内容。我不知道为什么,我知道这只是一件小事,但是下次重新启动时,一切都非常完美。

这里是0秒:

[11/30/2018 10:57:27 > 2f0a74: SYS ERR ] Job failed due to exit code -1
[11/30/2018 10:57:27 > 2f0a74: SYS INFO] Process went down, waiting for 0 seconds
[11/30/2018 10:57:27 > 2f0a74: SYS INFO] Status changed to PendingRestart
[11/30/2018 10:57:28 > 2f0a74: SYS INFO] Run script 'run.bat' with script host - 'WindowsScriptHost'
[11/30/2018 10:57:28 > 2f0a74: SYS INFO] Status changed to Running

这是重启后的运行:

[11/30/2018 10:59:07 > 2f0a74: SYS ERR ] Job failed due to exit code -1
[11/30/2018 10:59:07 > 2f0a74: SYS INFO] Process went down, waiting for 60 seconds
[11/30/2018 10:59:07 > 2f0a74: SYS INFO] Status changed to PendingRestart
[11/30/2018 11:00:09 > 2f0a74: SYS INFO] Run script 'run.bat' with script host - 'WindowsScriptHost'
[11/30/2018 11:00:09 > 2f0a74: SYS INFO] Status changed to Running

这是它的外观。 60秒重启时间。 为什么第一次是0?

1 个答案:

答案 0 :(得分:0)

我研究了Github Kudu repo中的WEBJOBS_RESTART_TIME配置设置。如果搜索了代码WEBJOBS_RESTART_TIME,您将发现为其定义的变量WebJobsRestartTime用作别名,如下所示。

public const string WebJobsRestartTime = "WEBJOBS_RESTART_TIME";

然后,继续搜索WebJobsRestartTime,有a code comment解释您怀疑的等待时间060

// The wait time between WebJob invocations is either WebJobsRestartTime (60 seconds by default) or if the WebJob
// Was running for at least 2 minutes there is no wait time.