Azure WebJobs totally rock! Think: “Cron jobs for the cloud”. You can write them to launch on demand, or schedule them as one-off or recurring jobs. Better yet, you can write them in a bunch of the supported languages - one of which is Node.js!

I’ve been working on a rebooting a little app I wrote years ago called Thriftebook, which aggregates publishers “Deal of the Day” stuff, but this time in Node.js and Angular (repo here). It’s pretty scratchy at the moment, but worth a look to get the idea. Well, the heart of an aggregator is a regularly polling job to go out and look for fresh data. Enter the Azure WebJob!

Light through clouds from Flickr via Wylio © 2010 Florin Gorgan, Flickr | CC-BY-SA | via Wylio

 

Packaging Up Your Node.js WebJob

The Node.js support for Azure WebJobs is first class - including support for npm dependencies. Just zip up your *.js files, with your root js file containing the code to run on schedule, and you’re done. I know very little about gulp, but decided it was probably worth putting together a gulp task to create my  little feedFetcher.zip for WebJob uploading:

https://gist.github.com/glenasmith/fcfe171dc79b5ad87de5

If I knew a bit more about Azure, I would probably launch a Powershell script to deploy the Webjob directly from gulp, but that’s for down the track.

Note that these days you don’t need to zip up your node_modules directory - you’ll get that stuff for free from package.json - which means your deployed zip will be nice and tiny.

Using the Right Portal

Now, for a the full set of Webjob options, you’re better off using the older Azure Management Portal rather than the newer one. The older one is the one that offer the full set of scheduling and recurring options which the newer one doesn’t yet support (at time of writing).

First you upload your zip, and tell Azure to “Run it on a schedule”, then the next UI page will let you specify the recurrence and frequency as shown below:

Azure WebJob Upload

And once you click that tick, your WebJob is up and running. Super awesome!

With my Azure job now nicely scraping sites nicely on the hour, it’s time to start work on a “watchlist” feature for Thriftebook