连续WebJobs和的CancellationToken [英] Continuous WebJobs and CancellationToken

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

问题描述

我没有得到令牌取消背后的机制和网络的工作。

I don't get the mechanics behind the cancellation token and the web jobs.

我知道我可以使用 Microsoft.Azure.WebJobs.WebJobsShutdownWatcher()。令牌获得令牌和 token.IsCancellationRequested 例如,当WebJobs被更新。

I know I can use Microsoft.Azure.WebJobs.WebJobsShutdownWatcher().Token to get the token and react on token.IsCancellationRequested eg when the WebJobs are updated.

情景:
连续工作,通过服务总线消息触发。
这项工作要求在我的数据层的方法。
这种方法确实一个蓝色的SQL数据库上的不同表一些更新。这种方法运行了大约两分钟。

Scenario: Continuous job, triggered by a service bus message. The job calls a method in my data layer. This method does some updates on different tables on an azure sql database. This method runs for about two minutes.

现在我将令牌传递到数据层和有没有同时被请求撤销我会做我的工作;否则我将结束我的更新。

Now I would pass the token to the data layer and there I would do my work while no cancellation is requested; else I would end my updates.

现在的问题:

做这项工作主机等待我的方法,直到它完成,然后停止?

Does the job host wait for my method until it is finished and then stops?

我必须设置stopping_wait_time的值(什么是默认呢?)足够高,以确保我的工作完成正常吗?

Do I have to set the "stopping_wait_time" to a value (what is the default anyway?) high enough to be sure my job finishes properly?

如果一个新的消息被写入到服务总线队列,这条信息尽管取消未决引发新的工作吗?

If a new message is written to the service bus queue, does this message trigger a new job despite the fact that a cancellation is pending?

感谢任何澄清!

推荐答案

没有的WebJob运行时不会等待你的方法来完成。取消令牌,可检索使用WebJobShutdownWatcher只允许被通知webjob正在停止。它是只允许一点点时间到code至正常关机。

No the WebJob runtime does not wait for your method to complete. The cancellation token that you can retrieve using the WebJobShutdownWatcher only allows you to be notified that the webjob is stopping. It is only allowing a bit of time to your code to shutdown properly.

默认的等待时间连续webjobs为5秒,但你可以使用stopping_wait_time设置增加了,如你所说。

The default wait time for continuous webjobs is 5 seconds, but you can increase it using the "stopping_wait_time" settings, as you suggested.

有关我所看到的,如果你的webjob正在停止,它不接受新的消息触发了,直到重新启动它。但我没有找到任何确认文档中这一点。

For what I have seen, if your webjob is stopping, it does not accept new message triggers anymore, until it is restarted. But I did not find anything confirming this point in the documentation.

有关webjobs正常关机此处描述: https://github.com/projectkudu/捻/维基/ WEB-乔布斯

Graceful shutdown for webjobs is described here: https://github.com/projectkudu/kudu/wiki/Web-Jobs

希望这有助于

朱利安

这篇关于连续WebJobs和的CancellationToken的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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