Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continuous WebJobs and CancellationToken

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!

like image 287
Herr häck Avatar asked Dec 30 '15 12:12

Herr häck


1 Answers

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

like image 198
Julien Corioland Avatar answered Nov 05 '22 04:11

Julien Corioland