Simply put, Azure WebJobs is compute on a managed platform. Learn about some benefits to using a WebJob in post-deployment actions through a step-by-step guide.
- [Narrator] WebJobs can be attached to your web app, and this will allow you to run programs or scripts to automate tasks. Typically, we would use WebJobs for maintenance tasks that do not affect our users. We have three deployment options for our WebJobs. Our first option is on demand, and as it states, we would run this as required. Next, we can go ahead and schedule our WebJobs. We can do this using CRON. If we do use CRON, Always On must be enabled.
We can also schedule our WebJobs using the classic portal using the Azure Scheduler. And finally, we can run our WebJobs continuously. These can be run on all instances, and as with CRON, the Always On must be enabled. The nice thing with our continuously run jobs is that we can debug them. There are several file types that we can use for our WebJobs. We can use the classic .cmd, or an .exe or those of you who remember batch files, the .bat's.
You can use a PowerShell script for your WebJob. You can use Bash, PHP, Phython, Node, and finally Java, whichever one you are most comfortable in. Let's go ahead and pop into Azure and take a look at setting up WebJobs. As you can see, we have logged into Azure. I happen to be in the DeployWebApps resource group. Now I'm going to attach a WebJob to Prodwebapp. And you'll find WebJobs under settings.
Click WebJobs to open the blade. As you can see, we do not have any WebJobs as of yet. We're going to go ahead and click Add to add one. Enter a descriptive name. Next, locate your file.
I happen to have a script ready to go called CleanUpLogs sitting on the Desktop. Then click Open. Next, we can choose our type. We have continuous and triggered. Let's go ahead and work with triggered first. In this case, you'll need a CRON job, and you'll have to provide a valid CRON expression for that. You can set a trigger to be scheduled or manual.
For our purposes, we're going to go ahead and go back to continuous. And here, for our scale, we have two options. We have a multi instance and a single instance. In the case of a single instance, only one instance of the WebJob will run, no matter how many instances are running in the app service. Whereas in multi instance, the job will run across all instances in the app service plan. Once you have all of this setup, click Okay. We can see here that the WebJob has been added, but we don't see it on our screen, so I'm going to go ahead and click Refresh.
There we are. And from here, we can go ahead and click Start, we can view the logs for the WebJob, or we can look at the properties of the WebJob. And that's all there is to adding WebJobs to your apps. As I've already mentioned, WebJobs are a great tool for performing routine maintenance on your Azure apps, because these jobs do not affect your users.
- Deploying Web Apps
- Creating App Service plans
- Deploying and moving apps
- Configuring app settings
- Managing Web Apps using PowerShell and CLI
- Configuring alerts
- Enabling diagnostic logs
- Retrieving and streaming logs
- Configuring Web Apps for scale and resilience