15

We have an Azure Website setup with a "staging" deployment slot, and we use a continuous Azure WebJob to process long-running background jobs. It appears that when you publish to the Website (and include the WebJob binaries), that the WebJob will restart itself if it was previously stopped.

Our current deployment process looks like the following:

  1. Deploy to STAGING
  2. Immediately & Quickly stop the WebJob on STAGING (try to prevent 2 WebJobs from processing messages)
  3. Smoke test and verify code on STAGING works
  4. Stop the PRODUCTION WebJob (let it drain off queue messages)
  5. Swap between PRODUCTION and STAGING
  6. Start the PRODUCTION WebJob (which was just the STAGING WebJob)

Is there a trick (say a flag file or something) to tell a WebJob NOT to start up after publishing?

ericb
  • 3,400
  • 1
  • 21
  • 21

3 Answers3

22

To deploy a continuous WebJob in a stopped state simply add a file called disable.job at the root of your WebJob (binaries), this will tell the framework that the WebJob is currently stopped.

To view this behavior you can simply stop a continuous WebJob and see that this file is generated and placed at the WebJob's directory.

Amit Apple
  • 9,034
  • 41
  • 50
  • 1
    Just tested this and it works great. I added a 'disable.job' file to the root of my c# console project and set its build action to 'Content'. – ericb Jul 02 '14 at 20:09
  • @Amit I could gave sworn that until just recently, when a site was published the webjob's state would stay the same - if it's stopped, keep it stopped; if it's running, keep it running. The fact that I'm publishing a new version of the web app code and/or webjob code shouldn't be seen as an assumption by the framework that the running state of the webjobs should be changed. FYI I posted on this here https://stackoverflow.com/questions/42380853/stopped-azure-webjobs-are-starting-following-publishing-of-web-app. – Matthew Feb 22 '17 at 05:43
22

You can add Application Setting WEBJOBS_STOPPED to your staging slot and set it to 1. Make this setting 'Slot Setting' so that it is not swapped with production.

Bharat
  • 3,491
  • 1
  • 22
  • 22
0

AFAIK, there is no out of the box solution for that. However, you can set an app setting and have the webjob code check for it when it starts. Also, you can use the HTTP_HOST variable to figure out the environment.

Victor Hurdugaci
  • 28,177
  • 5
  • 87
  • 103
  • That's a good idea but if you set a Continuous job to run but you actually stop it instead of calling RunAndBlock(), Azure should restart it as it saw it closed. Isn't this assumption correct? – jsgoupil Jun 24 '15 at 03:06