In this video, Sharon provides an overview of Azure WebJobs followed by a demonstration of how to implement, configure, and schedule a WebJob.
- [Instructor] WebJobs are programs or scripts that are used to implement background tasks in your web app. They can be run on demand or triggered. They can be run continuously or we can run them on a schedule. Common use cases for WebJobs include image processing, queue processing, file maintenance, or RSS aggregation. There are several supported file types for WebJobs including .cmd, .bat, and .exe, PowerShell, Bash Shell, PHP, Python, Node.js, or a Java archive.
Let's go ahead and pop into Azure and create a WebJob. You'll notice that I'm already in the LIL messaging resource group and I've already created an Azure web app within the Azure app service plan. Let's go ahead and open up that web app. In order to implement WebJobs, you'll scroll all the way down to WebJobs and it's under settings. Next, go ahead and click on add as we don't have any WebJobs already.
We're going to go ahead and provide a name to this WebJob. Next, we're going to select a file. I'm going to use a ps1 or PowerShell script. Next, we can select our type. Is it continuous or triggered? And finally, we can select on the scale, so we have a multi-instance or a single instance. A multi-instance will scale the WebJob across all instances in that app service plan whereas a single instance will only use one WebJob and will not scale across all the instances.
I'm going to leave it at multi-instance. And for our demonstration, I'm going to go ahead and click on triggered. That way, I can continue to build this out. Next, we have our triggers, so these can be scheduled or manual, whichever one you prefer. I'm going to leave it at scheduled. And next, we can go ahead and create a Cron expression. And as a refresher of a Cron expression for those of you who haven't seen it in a while, we configure this using second, minute, hour, day of month, month and day of week.
For example, if I use zero, 15, 13, asterisk, asterisk, asterisk, that will translate to run this WebJob everyday at 1:15. You could also schedule this within the script if you wanted to do so, but here we're taking advantage of the Azure scheduler. Go ahead and click OK. Once I refresh the page, you'll notice that our WebJob is now available to us.
It may take a few moments for that WebJob to be available to you. If you click over in properties, you'll see the web hook, the username, and the password. I'm going to go ahead and close the properties blade. If I select the WebJob, I now have the option to run it or delete it. I can also view the logs for that WebJob and we can see that this WebJob has never run. And that's all there is to it to create a WebJob which you can use to implement background tasks on your web app.
- Creating compute-intensive applications
- Creating long-running applications
- Implementing messaging systems
- Azure Service Bus relays
- Using Azure Storage queues
- Creating an Azure Event Hub
- Creating Azure WebJobs
- Managing cloud environments with Azure Active Directory Domain Services