简体   繁体   中英

Webjob of staging slot not stopping after a pipeline deploy in Azure Devops

In some of the deploys i'm doing to an App Service resource that contains 2 slots (a production and staging slots), the webjob of staging is not stopping after the swap of slots.

Basically i have in my pipeline the following tasks:

## Start App Service (staging)
- task: AzureAppServiceManage@0
  displayName: 'Start Azure App Service: some-app-webjob (staging)'
  inputs:
    azureSubscription: 'xxx'
    Action: 'Start Azure App Service'
    WebAppName: 'some-app-webjob'
    SpecifySlotOrASE: true
    ResourceGroupName: 'some-rg-app-webjob'
    Slot: staging
##Start staging continuous webjob
- task: AzureAppServiceManage@0
  displayName: 'Start all continuous webjobs: some-app-webjob (staging)'
  inputs:
    azureSubscription: 'Subscrição do Visual Studio Enterprise(c9f20c2b-15cf-41fb-8122-ddf095c6db02)'
    Action: 'Start all continuous webjobs'
    WebAppName: 'some-app-webjob'
    SpecifySlotOrASE: true
    ResourceGroupName: 'some-rg-app-webjob'
    Slot: 'staging'

## Swap Slots (staging to production)
- task: AzureAppServiceManage@0
  displayName: 'Swap Slots: some-app-webjob'
  inputs:
    azureSubscription: 'xxx'
    WebAppName: 'some-app-webjob'
    ResourceGroupName: 'some-rg-app-webjob'
    SourceSlot: staging
    TargetSlot: production

# Stop WebJobs running Staging
- task: AzureAppServiceManage@0
  displayName: 'Stop all continuous webjobs: some-app-webjob (staging)'
  inputs:
    azureSubscription: 'xxx'
    Action: 'Stop all continuous webjobs'
    WebAppName: 'some-app-webjob'
    SpecifySlotOrASE: true
    ResourceGroupName: 'some-rg-app-webjob'
    Slot: staging
    
## Stop App Service (staging)
- task: AzureAppServiceManage@0
  displayName: 'Stop Azure App Service: some-app-webjob (staging)'
  inputs:
    azureSubscription: 'xxx'
    Action: 'Stop Azure App Service'
    WebAppName: 'some-app-webjob'
    SpecifySlotOrASE: true
    ResourceGroupName: 'some-rg-app-webjob'
    Slot: staging

If i go look to my slot staging the app service is stopped. But sometimes the workjob keeps running while it shouldn't. since i have a task that should top all continuous webjobs after the swap with production.

In summarise this can happen:

  • continuous webjob in slot staging running
  • continuous webjob in slot production running

After searching I found this github thread https://github.com/projectkudu/kudu/issues/1886 It indicates that webjobs are running in scm site which is not affected by the stop site command. Still, I have a task that supposedly stops all continuous webjobs.

Is there any reason for this to happen? How can we prevent this? I don't want an webjob with old code running after a deploy.

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.

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

This is what happens when you swap a source slot (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 (ie '/'), 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.

I don't want an webjob with old code running after a deploy.

  • Check if you have a stage environment (add -stage to the Webapp name) and if so go in to the Azure management portal and stop them.

  • It is not enough to stop the Webapp, you must stop the WebJobs directly. This is done (in the new portal) under Settings->WebJobs and then right-clicking on the webjobs name selecting stop.

Please refer Azure Web Apps (Websites) Deployment Slots for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM