Skip to content

Instantly share code, notes, and snippets.

@mitchdenny
Created March 15, 2013 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitchdenny/5167498 to your computer and use it in GitHub Desktop.
Save mitchdenny/5167498 to your computer and use it in GitHub Desktop.
Some code that shows how to implement background execution in Node running on Windows Azure (or iisnode generally).
var status = {
started: Date.now(),
heartbeat: Date.now(),
runtime: null
};
var heartbeater = function() {
status.heartbeat = Date.now();
status.runtime = status.heartbeat - status.started;
setTimeout(heartbeater, 1000);
};
setTimeout(heartbeater, 1000);
var http = require('http')
var port = process.env.PORT || 1337;
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'application/json' });
var statusJSON = JSON.stringify(status);
res.end(statusJSON);
}).listen(port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment