Continuous WebJobs and CancellationToken

寵の児 提交于 2020-01-14 08:00:08

问题


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

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.

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.

Now the questions:

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

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?

Thanks for any clarifications!


回答1:


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.

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

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.

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

Hope this helps,

Julien



来源:https://stackoverflow.com/questions/34529299/continuous-webjobs-and-cancellationtoken

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!