如何在不删除已部署作业的前提下暂停Azure WebJob?
Hey there, I totally get your frustration—having to delete and redeploy a WebJob just to pause it temporarily sounds like a huge hassle, and you’re right to question that approach. The good news is that modern Azure WebJobs have several built-in ways to pause/resume without losing your deployment. Here are the most practical methods:
1. Use Azure Portal Controls (Quickest for Manual Actions)
- For Continuous WebJobs:
Navigate to your WebJob in the Azure Portal, go to the Properties tab, and change the Run Mode fromContinuoustoOn Demand. This will immediately stop the WebJob from running. To resume it, just switch the mode back toContinuous. - For Triggered WebJobs:
- If it’s a schedule-based job (using CRON), you can temporarily update the CRON expression to a far-future time (like
0 0 1 1 1 *for once a year) to effectively pause it. - Alternatively, head to the Triggers section of your WebJob and manually disable the trigger. When you’re ready to resume, re-enable it.
- If it’s a schedule-based job (using CRON), you can temporarily update the CRON expression to a far-future time (like
2. Azure CLI Commands (Great for Automation or Scripting)
If you prefer using command-line tools, these commands let you pause and resume WebJobs in seconds:
- Pause a continuous WebJob:
az webapp webjob continuous stop --name <your-webjob-name> --resource-group <your-resource-group> --webapp-name <your-app-service-name> - Resume a continuous WebJob:
az webapp webjob continuous start --name <your-webjob-name> --resource-group <your-resource-group> --webapp-name <your-app-service-name> - Disable a triggered WebJob:
az webapp webjob triggered disable --name <your-webjob-name> --resource-group <your-resource-group> --webapp-name <your-app-service-name> - Enable a triggered WebJob:
az webapp webjob triggered enable --name <your-webjob-name> --resource-group <your-resource-group> --webapp-name <your-app-service-name>
3. App Settings Toggle (No Code Changes Needed)
You can add a custom application setting to your App Service to control the WebJob’s execution:
- Go to your App Service in the Azure Portal → Configuration → Application settings.
- Add a new setting like
WEBJOB_PAUSEDwith a value oftrue. - Update your WebJob code to check for this setting at startup—if it’s
true, skip the core job logic (or exit immediately). - To resume, just change the setting value to
false(or delete it) and restart the WebJob.
This method is perfect if you want to keep the WebJob deployed but prevent it from running temporarily, without modifying or redeploying code.
4. Azure Automation Runbooks (Scheduled Pause/Resume)
If you need to pause the WebJob automatically for specific periods (e.g., every night for 8 hours), set up an Azure Automation Runbook:
- Create a PowerShell or Python script that uses Azure’s management APIs to stop/start the WebJob.
- Schedule the Runbook to execute at your desired times using a time trigger.
Why Old Forums Suggest Deleting?
Those recommendations are likely outdated—early versions of Azure WebJobs had limited pause/resume functionality, forcing users to delete and redeploy. But modern Azure has addressed this gap, so you don’t need to resort to that drastic step anymore.
内容的提问来源于stack exchange,提问作者ezycoder

