Reputation: 10201
When I swap deployment slots in Azure, do the web jobs restart? If so, do they restart with the destination configuration or source configuration values?
In my case, I don't want the web jobs to run in the staging slot. To deal with this, I have the following code:
public static void Main()
{
// Only run web jobs when configured
bool enableWebJobs = false;
bool.TryParse(ConfigurationManager.AppSettings["EnableWebJobs"], out enableWebJobs);
if (enableWebJobs)
{
var host = new JobHost();
host.RunAndBlock();
}
else
{
// Sleep so the Azure web jobs platform doesn't try to continually restart the process
while (true)
{
Thread.Sleep(60000);
}
}
}
I'm just unsure if the web jobs will be restarted after the swap with the correct AppSettings. If not, then this won't work at all as EnableWebJobs will remain false.
Upvotes: 1
Views: 1201
Reputation: 6425
The Configuration is swapped too so your code will not work as you hoped.
Using Amit Apple's post How to prevent Azure webjobs from being swapped in Azure website production <--> staging slots
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)
I have disabled webjobs in staging with this sticky slot setting.
Looking at the webjobs logs in the Kudu panel, the webjobs fire up when the app is deployed and are not affected by the actual swap (which AFAIK is just the load balancer routing to the new live/stage).
edit: I am wrong. There is a restart as part of the swap. (see Understanding site swaps) namely:
Here is what happens when you swap a source slot (let's call it 'Staging') into a target slot (Production).
First, the Staging site needs to go through some setting changes for App Setting and Connection Strings that are marked as 'slot'. There are also other changes related to source control that may need to be applied. This causes the Staging site to restart, which is fine.
Next, the Staging site gets warmed up, by having a request sent to its root path (i.e. '/'), and waiting for it to complete.
Now that the Staging site is warm, it gets swapped into Production. There is no down time, since it goes straight from one warm site to another one.
Finally, the site that used to be Production and is now Staging also needs to get some settings apply, causing it to restart. Again, this is fine since it happens in the staging site.
Upvotes: 3