连续WebJob stop_wait_time被忽略了吗? [英] Continuous WebJob stopping_wait_time ignored?

查看:84
本文介绍了连续WebJob stop_wait_time被忽略了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我昨天的问题(连续的Web作业和CancellationToken )之后,我想我现在已经了解了连续WebJobs的处理和正常关闭并进行了一些测试.

After my yesterday's question (Continuous WebJobs and CancellationToken) I thought now I've understand the handling of continuous WebJobs and graceful shutdown and did some testing.

其他信息

有了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在服务器上设置了Stop(停止),在仪表板中的以下条目是:

At Thu, 31 Dec 2015 07:00:23 GMT I put a Stop to the Server, the following entries in the Dash Board are:



    [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

我正在运行的作业立即结束,没有任何更多信息. 我函数的最后两行代码是记录到仪表板并将条目写入存储表.这些条目均未写入...我已经重试了几次,并且每次在5秒钟之内Job主机都停止了.所以:

And my running job ends at once without any further information. The last two lines of code of my function are the logging to the dashboard and writing an entry into a storage table. None of these entries are written... I've retried several times and everytime within 5 seconds the Job host stops. So:

问题

对于连续的Web作业,是否会优雅地忽略"stopping_wait_time"值?

Is the "stopping_wait_time" value gracefully ignored for continuous WebJobs?

推荐答案

连续作业和触发作业都使用stopping_wait_time设置.您可以看到连续作业运行者如何使用此设置在源代码中.

The stopping_wait_time setting is used by both Continuous and Triggered jobs. You can see how the Continuous job runner employs this setting here in the source code.

我上传了一个有效示例,该示例演示了正常关机此处.在该示例中,我将关闭超时重写为60秒,并验证了我的工作功能能够执行30秒的关闭活动,而不会被杀死.

I've uploaded a working sample demonstrating graceful shutdown here. In that sample I override the shutdown timeout to 60 seconds, and verify that my job function is able to perform 30 seconds of shutdown activity w/o being killed.

请下载该示例并尝试.您还可以按照上面链接的示例自述文件中的详细说明在本地运行该示例.我还在此内联了示例函数,展示了如何使用CancellationToken:

Please download that sample and try it. You can also run the sample locally as detailed in the sample readme linked above. I also inline the sample function here showing how to use the 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秒正常关闭逻辑成功运行,如控制台输出所示:

This function's 30 seconds of graceful shutdown logic runs successfully, as shown by the console output:

  • [12/31/2015 17:15:08> 951460:SYS INFO]状态已更改为正在停止"
  • [2015年12月31日17:15:09> 951460:信息]功能已被取消.正在执行清理...
  • [2015年12月31日17:15:39> 951460:信息]功能已取消,并已正常终止.
  • [12/31/2015 17:15:39> 951460:INFO]功能成功完成.
  • [12/31/2015 17:15:39> 951460:INFO]作业托管已停止
  • [2015年12月31日17:15:39> 951460:SYS INFO]状态已更改为成功"
  • [12/31/2015 17:15:39> 951460:SYS INFO]状态已更改为已停止"
  • [12/31/2015 17:15:08 > 951460: SYS INFO] Status changed to Stopping
  • [12/31/2015 17:15:09 > 951460: INFO] Function has been cancelled. Performing cleanup ...
  • [12/31/2015 17:15:39 > 951460: INFO] Function was cancelled and has terminated gracefully.
  • [12/31/2015 17:15:39 > 951460: INFO] Function completed succesfully.
  • [12/31/2015 17:15:39 > 951460: INFO] Job host stopped
  • [12/31/2015 17:15:39 > 951460: SYS INFO] Status changed to Success
  • [12/31/2015 17:15:39 > 951460: SYS INFO] Status changed to Stopped

这篇关于连续WebJob stop_wait_time被忽略了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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