Microsoft Azure is the Cloud computing platform and infrastructure created by Microsoft. Azure is known for building, deploying, and managing applications and services through a global network of Microsoft-managed data centers. WebJobs in Microsoft Azure is considered to be a feature of Azure App Service. It lets you run a program or script in the same context as a web app, API app or mobile app. Azure WebJobs is a feature provided by the cloud computing platform of Microsoft which enables you to run programs/scripts as background processes by a part of Azure websites.
The scripts or programs could be written in any of the following file types:
- .cmd, .bat, .exe (using windows cmd)
- .ps1 (using powershell)
- .sh (using bash)
- .php (using php)
- .py (using python)
- .js (using node)
- .jar (using java)
Creating and deploying a Sample WebJob in Azure
Let us explore the creation and deployment of a sample WebJob in Azure. We will create a sample console application for the demonstration. This will be a “HelloWorld” Azure WebJob.
Here’s the snapshot of the console application solution:
And the Program.cs
Now, let us try deploying this WebJob to Azure.
Right click the solution and choose the “Publish as Azure WebJob” option:
This will take you to the following screen:
We can provide the settings for the WebJob, here. This includes the WebJob name and the run mode.
We have provided the WebJob a name and that is “HelloWorld”. We, now have three options to choose the run mode.
- Run on Demand
- Run Continuously
- Run on Schedule
The run mode needs to be determined based on the WebJob’s specific requirement. Some WebJobs need to be run all the time. This could be configured as “Run Continuously”. Some WebJobs need to be run only when the user desires to trigger them and this could be configured as “Run on Demand”. Some WebJobs might need to run on specific intervals or a schedule and is configured as “Run on a Schedule”.
For the demonstration, let us choose the option “Run on Demand”.
Once this is chosen, click “Ok” button to proceed.
In the next screen, choose the Azure App service to which your WebJob needs to be deployed:
Once the App service is selected, click on the “Publish” option to get the WebJob published in Azure.
Monitor the Azure App Service Activity window in Visual Studio to track the WebJob that is published. Once the publishing is successful, login to the respective azure account and choose the App service.
Choose the “WebJobs” option from the selected App service:
The “HelloWorld” WebJob will be listed as follows:
Select the “Run” option from the top to execute the WebJob
After the WebJob is executed, the status will be changed to:
To see the logs of the WebJob execution, click the “Logs” option from the top. This will navigate to a new tab with the log information of the respective WebJob as follows:
And with this, we have completed the creation, deployment and running our first WebJob in Azure!
Azure WebJobs are known to provide a way to run background tasks either continuously or on schedule. The WebJobs run on the same virtual machine that your web app is running on. They support a variety of file formats like exe, cmd, bat, sh, php, py and js. WebJobs can be deployed together with your web application and you are able to manage, view and trigger all jobs through Azure portal.
Sr. Software Engineer, RapidValue