Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Azure webjobs from being swapped in Azure website production <--> staging slots

Tags:

I have an Azure website with a production and staging slot with multiple instances.

I run several Azure webjobs on the site, some of which are triggered others that are continuous.

I understand triggered webjobs will only run once on one instance.

My current setup is:

  • Production site has no deployment other than swapping from staging

  • Staging website is setup to continuous deployment from bitbucket

  • Webjobs are deployed from within VS to production slot using "publish to Azure" (since AFAIK there is no support for continuous deployment of webjobs that are schedule based)

  • The VS solution for the website is different from the VS solution containing webjobs

I noticed when I swap production and staging, webjobs are also swapped! I realized this when I had deployed a new webjob to production and subsequently did a website deployment followed by a swap, the newly deployed webjob was no longer in the production slot!

My questions:

  1. is it possible to prevent webjobs from swapping between production and staging (webjobs are really entirely different pieces of code than the website)

  2. What exactly is swapped for webjobs? Binaries? Schedule? Both ?

  3. how do i prevent all webjobs from running on the staging slot? My webjobs do not need to be highly available and i can test them offline easily.

  4. If i VS deploy webjobs to the staging slot and do a swap, then the current staging slot will be missing the deployed webjob and I'll lose it when i do my next website update, so where should i be deploying my webjobs?

There is a related thread but it assumes the webjob is deployed simultaneously with a website which is not what I have currently.

I really like websites and webjobs, but it seems the story related to continuous independent deployment of webjobs and websites is broken.

Would really appreciate advice!

Thanks

like image 672
Sandeep Phadke Avatar asked Jun 26 '15 02:06

Sandeep Phadke


People also ask

Which Azure websites feature should you enable for continuously running WebJobs?

If you set the web app that hosts your job to run continuously, run on a schedule, or use event-driven triggers, enable the Always on setting on your web app's Azure Configuration page. The Always on setting helps to make sure that these kinds of WebJobs run reliably.

Which of the following settings is not swapped when you swap an app?

Settings that aren't swapped:Non-public certificates and TLS/SSL settings. Scale settings. WebJobs schedulers. IP restrictions.

What is swap slot in Azure?

Swap operations During a swap, one slot is considered the source and the other the target. The source slot has the instance of the application that is applied to the target slot.


2 Answers

Azure websites deployment slots are not an easy concept to understand, together with WebJobs it gets a little bit more difficult.

I suggest reading the following post to get a better understanding on deployment slots - http://blog.amitapple.com/post/2014/11/azure-websites-slots/ (including the comments section for useful information)

To get a better understanding on how WebJobs work and deployed see this post - http://blog.amitapple.com/post/74215124623/deploy-azure-webjobs/

It is important to understand that:

  1. When swapping deployment slots you actually swap the content/files of the website between the 2 slots.
  2. WebJobs are part of the website content.

So when you swap the slot you actually swap the website files including the WebJob.

Note it is a bad practice to deploy a WebJob directly and not as part of your website files/repository, this is probably the cause of issues you are having.

To prevent WebJobs from running on the staging slot you can add an app setting called WEBJOBS_STOPPED and set it to 1 (in the azure portal). (source). Make sure this app setting is sticky to the slot otherwise it'll propagate to the production slot.

like image 163
Amit Apple Avatar answered Sep 23 '22 02:09

Amit Apple


The by far easiest solution to this problem is to have a separate Web App for your Web Job. Just place the Worker Web App on the same Azure Service Plan and you will have two separate Web Apps running on the same machine(s).

web-app web-app-worker

like image 37
Niklas Arbin Avatar answered Sep 23 '22 02:09

Niklas Arbin