Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens to "in-progress" jobs when you deploy a webjob?

Subject says it all really :) Say I've got a pretty busy Azure continuous webjob that is processing from an azure Queue:

    public static void ProcessQueue([QueueTrigger("trigger")] Info info)
    { .... }

If I re-deploy the webjob, I can see that any currently executing job seems to be aborted (I see a "Never Finished" status). Is that job replayed after I release or is it lost forever?

Also, is there a nice way to make sure that no jobs are running when we deploy webjobs, or is it up to the developer to code a solution to that (such as a config flag that is checked every run).

Thanks

like image 514
Matt Roberts Avatar asked Jan 20 '15 10:01

Matt Roberts


People also ask

How do you monitor a WebJob?

You can monitor Web Jobs using 3rd party tool like CloudMonix or App Insights Web Tests(it is a part of Azure Monitor). With App Insights Web Tests you need Kudu Web Jobs API to get the current status of the web job, e.g. Call the Kudu API from your App Insights Web Tests.

What is a WebJob in Azure?

WebJobs is a feature of Azure App Service that enables you to run a program or script in the same instance as a web app, API app, or mobile app. There is no additional cost to use WebJobs. You can use the Azure WebJobs SDK with WebJobs to simplify many programming tasks.


1 Answers

When a WebJob that uses the WebJobs SDK picks up a message from a queue, it acquires it with a 10 minutes lease. If the job process dies while processing the message, the lease expires after 10 minutes and the message goes back in the queue. If the WebJob is restarted, it will pick that message again. The message is only deleted if the function completes successfully.

Therefore, if the job dies and restarts immediately, like in the case of a redeploy, it might take up to 10 minutes to pick again the message. Also, because of this, it is recommended to either save state yourself or make the function idempotent.

In the WebJobs Dashboard you will see two invocations for the same message. One of them will be marked as Never Finished because the function execution never completed.

Unfortunately, there is no out of the box solution to prevent jobs from running during deploy. You would have to create your own logic that notifies (through a queue message?) that a deploy is about the start and then aborts the host. The host abort will wait for any existing function to stop and will prevent new ones from starting. However, this is a very tricky situation if you have multiple instances of the webjob because only one of them will get the notification.

like image 130
Victor Hurdugaci Avatar answered Oct 19 '22 23:10

Victor Hurdugaci