Start stop azure webjobs through PowerShell or Azure CLI

 

Start stop azure webjobs through PowerShell or Azure CLI

Azure WebJobs is a feature of Azure App Service that allows you to run a program or script in the same context as your web app. This allows you to perform background tasks like image processing, file maintenance, and message handling. 

In this blog, we will learn how to start and stop Azure WebJobs using PowerShell and Azure CLI. 

Prerequisites

To follow this blog, you will need the following: 

  • An Azure account with an active subscription
  • A web app with at least one WebJob deployed
  • PowerShell installed on your machine
  • Azure CLI installed on your machine

Step 1: Start and Stop Azure WebJobs using PowerShell

First, let's learn how to start and stop Azure WebJobs using PowerShell.

 

Open PowerShell on your machine.
Connect to your Azure account using the following command:   
                                               
Connect-AzAccount

Enter your Azure credentials when prompted. 

Set the context to your web app using the following command:    

Set-AzContext -SubscriptionId "<subscription-id>" -ResourceGroupName "<resource-group-name>" -Name "<web-app-name>"     

Replace "<subscription-id>", "<resource-group-name>", and "<web-app-name>" with the appropriate values.

To start a WebJob, use the following command:
Start-AzWebAppContinuousWebJob -Name "<webjob-name>" -WebJobType "<webjob-type>"


To stop a WebJob, use the following command: 
 
Stop-AzWebAppContinuousWebJob -Name "<webjob-name>" -WebJobType "<webjob-type>"

 That's it! Now you can use PowerShell to start and stop your Azure WebJobs as needed.


Step 2: Start and Stop Azure WebJobs using Azure CLI

Next, let's learn how to start and stop Azure WebJobs using Azure CLI.

 

Open a command prompt or terminal on your machine.

Connect to your Azure account using the following command:

az login

Enter your Azure credentials when prompted. 

Set the context to your web app using the following command: 

az webapp up -n "<web-app-name>" -g "<resource-group-name>"

Replace "<web-app-name>" and "<resource-group-name>" with the appropriate values.

 To start a WebJob, use the following command:

az webapp webjob continuous start --name "<web-app-name>" --job-name "<webjob-name>"

Replace "<web-app-name>" and "<webjob-name>" with the appropriate values.

 

To stop a WebJob, use the following command:

az webapp webjob continuous stop --name "<web-app-name>" --job-name "<webjob-name>"

Replace "<web-app-name>" and "<webjob-name>" with the appropriate values.

 

That's it! Now you can use Azure CLI to start and stop your Azure WebJobs as needed.

 

Conclusion

In this blog, we learned how to start and stop Azure WebJobs using PowerShell and Azure CLI. 

These tools provide a simple and efficient way to manage your WebJobs in the Azure cloud. By following these steps, you can start and stop your WebJobs as needed and keep your web app running smoothly.


No comments:

Post a Comment