How to Accelerate Background Tasks in the Cloud?

Sagar Rao
3 min readFeb 17, 2017

AzureWebjobs helps us quickly develop, deploy, and run background tasks in the cloud. Close integration with utility components cuts down the development time to half.

Traditionally, batch jobs are developed using 3rd party libraries like Hangfire or Quartz. There is a lot of boilerplate coding, and heavy configurations required to implement these APIs. Creating Jobs, Schedules, Triggers, Logging, and Handling failure manually is laborious. Also, maintaining these parameters becomes a nightmare as the application grows and scales.

However, Azure Webjobs shifts the configuration burden from developers to the framework. For example, a batch job function can process a message from a queue with minimal specification. New messages in the queue will automatically trigger delegated functions.

All we have do is specify which queue to listen for. Based on the frequency and configuration (very little) -Webjobs will automatically pool for the queue messages.

5 benefits of using Azure Webjobs in the cloud.

  1. Easy Setup.
  2. Faster Development.
  3. Seamless Deployment.
  4. Built-in Logging.
  5. Extensible Components.

Easy setup:

Unlike custom batch jobs, we do not need to persist jobs and schedules in databases. The underlining Webjobs framework will automatically manage for us. Any changes to these schedules are automatically updated.

Faster development:

Like any other function, you can start writing your batch processing logic without the overhead of implementing any IJob or ISchedules. In fact, you can write this function in any of languages Azure currently supports and upload it.

Seamless Deployment:

There 2 major methods to deployWebjobs.

Manual

  1. Zip up your code
  2. Upload it to the Azure app service.
  3. Select your schedules.

Auto

  1. Add AzureWebjobs to your project.
  2. ReferenceWebjobs to the main project.
  3. Select your schedules.

Manual deploy could be used in cases of smaller code bases, and functions that have a single responsibility.

Auto-deploy will publish the web job everytime the project is deployed.

Built-in Logging:

Azure portal actually logs all the run events ofWebjobs functions automatically. These logs indicate important information like…

  1. Start, and end times when aWebjobs ran.
  2. Success or Failures status of aWebjobs.
  3. Context information likeWebjobs id.
  4. Retrial attempts (in case of failures).
  5. Next due on (scheduled).
  6. Multi-threading.

Extensible for components:

Webjobs in combination with each of the below components lessens boilerplate code.

  1. Email: Use SendGrid attributes to define your to, from, subject to send out e-mails.
  2. Sms: Use Twillo components on top of functions to send out SMS as output a result of a trigger. Like on receiving a queue message or on a schedule.
  3. Queues: Trigger a function listening to a queue for messages by declaring the queue name on the function.Webjobs will pool according to the frequency of the data. This pooling could be adjusted in case of over-utilization.
  4. Blob: Trigger a function of receiving a blob or as output as a blob. Blobs are serialized files. We can create blob object in any type of content we want.
  5. File: Trigger a function on file attribute changes or file creations.
  6. Timer: Run a function every often or on a schedule.
  7. No Automatic: Create a manual trigger function. Useful with Web API integration or with webhooks.

Originally published at code.sagar.buzz on February 17, 2017.

--

--

Sagar Rao
Sagar Rao

Written by Sagar Rao

I write code for living and blogs for sharing.

No responses yet