In this post, I will explain how you can use WebJobs to execute tasks on Azure App Service.
You might require some sort of task to run in Azure, for example, when I upload an image via a Web App, a background task will pick up that image, do something to it, and then email me a link to download the results.
This sort of task was historically done by a WebJob, a task that could execute in the abstracted virtual machine environment of Azure App Services. A WebJob, in short, is some script or executable that can be run continuously, manually started, or triggered on a scheduled basis.
WebJobs run in Azure App Service plans. There are two considerations, especially for larger applications:
Azure Functions are similar to WebJobs because they allow you to perform some task in the background. Functions are triggered by a schedule or event; in other words, an instance of the Function is instantiated by Azure in response to something happening to perform a task. When that task is completed, the instance disappears. There is no server, so there is no big incremental cost; instead you pay for each second of Function run time. On the plus side, smaller tasks should reduce your Azure costs and Functions can scale beyond the limitations of your App Service plans. On the downside, there is a potential for a huge bill if your Functions go wild. Azure App Service plans have a fixed/predictable per-instance (virtual machine) cost.
So while Functions are hot right now, WebJobs still have an important role to play, especially when one is migrating existing applications to Azure.
This process is quite simple. Create a new Web App, which is confusingly called an App Service in the Azure Portal. Open the App Service and open Settings > WebJobs.
Click + Add and a Add WebJob blade will appear. Enter the following information:
If you selected Continuous you have two options for Scale:
If you select Triggered, then you can choose between:
Note that you must ensure that Always On is enabled in the Application Settings of the Web App before adding a continuous or scheduled WebJob.
Click OK, your script/executable will be uploaded, and the WebJob will be created.