Search code examples
.netazureazure-web-app-servicehangfire

Only pickup Hangfire task on server based on the environment (swap slot)


We're running Hangfire for websites using Azure App Services. We also use the wonderful swapping mechanism. That means instead of deploying to production, we deploy a slot and swap it once the deployment is finished.

The problem is, that the swap slot keeps picking up jobs from hangfire.

I want to make sure that only the production slot is actually executing hangfire jobs. The challenge is that the status whether it is production or not happens without an app restart (in both directions).

I can set slot sticky app settings in Azure so with that I can identify whether I am in production mode or not. It just leaves me with the key question:

How do I enable and disable my app from processing jobs at run-time?


Solution

  • We solved this by separating the Hangfire service out to it's own App Service with a different deployment strategy. For the Hangfire service we hard stop the service, deploy and then start the service again.