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

后端 未结 3 1320
说谎
说谎 2020-12-09 09:14

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

相关标签:
3条回答
  • 2020-12-09 10:00

    Here's Amit's answer to #3 using PowerShell,

    Function Disable-AzureSlotJobs($SiteName, $Slot = 'staging')
    {
        $site = Get-AzureWebsite -Name $SiteName -Slot $Slot
        $site.AppSettings.WEBJOBS_STOPPED = "1"
        Set-AzureWebsite -Name $SiteName -Slot $Slot -AppSettings $site.AppSettings
        Set-AzureWebsite -Name $SiteName -SlotStickyAppSettingNames @("WEBJOBS_STOPPED")
    }
    
    'MySite1', 'MySite2', 'MySite3' | % { Disable-AzureSlotJobs $_ }
    
    0 讨论(0)
  • 2020-12-09 10:01

    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.

    0 讨论(0)
  • 2020-12-09 10:16

    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

    0 讨论(0)
提交回复
热议问题