Trace  Hoeger

Trace Hoeger


Handling Scheduled and Continuous Workloads Through Azure WebJobs

What are WebJobs?

If you have ever built an application of anything more than small scale, you know that you need to have services running in the background that can handle workloads that either are required to execute in the background or are required to run on scheduled intervals. There are several solutions available for this problem in on-premise and cloud worlds. You can use a windows service or have an HTTP endpoint triggered by a cron service such as Windows Task Scheduler to schedule a task. For Microsoft Azure deployments, if your demands are more biased towards PaaS flavors, you can use worker roles, which come deployed in their own virtual machines, to continuously keep executing workloads in the background. For IaaS based workloads, you may choose to deploy “cron” services and jobs on VMs or install your Windows Services on VMs.

All the approaches mentioned above carry a ton of overhead and have some associated costs as they require their own VMs to execute in. For a small to moderate workload, such as a script or executable, that you want to either execute at certain intervals or run continuously, Azure WebJobs are a simple and quick solution. The best thing is that they have no costs associated with them (FREE!!). If you have a nicely designed web application which has some CPU cycles and some bandwidth to spare, you can use the unused infrastructure to execute small workloads in the background by piggybacking a WebJob on your WebApp. I use WebJobs for sending out mails to you when you register (a triggered workload) or when I post a new blog (a triggered workload) or clean up the subscriber list(a scheduled workload). WebJobs execute within the context of your WebApp therefore, you don’t need to configure connection strings or application settings in the configuration files of WebJob if you have provisioned the settings already in the associated WebApp. For deployment, you can keep enjoying the benefits of continuous deployment though Visual Studio or GIT. To make a WebJob execute, you just need to place the job binaries in the proper location within the web application. Exploiting this very feature, people have come up with solutions to deploy WebJobs through FTP etc. such as one here.

You can run programs or scripts in WebJobs in your App Service web app in three ways: on demandcontinuously, or on a schedule. The following is how I use WebJobs to send emails to my subscribers and perform a nightly cleanup of my subscriber list.

#azure webjobs #handling scheduled #continuous workloads

Handling Scheduled and Continuous Workloads Through Azure WebJobs