Created
December 28, 2011 02:00
-
-
Save ritch/1525799 to your computer and use it in GitHub Desktop.
Ring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// start node.js processes on a distributed network | |
// makes sure the process is always available, even if | |
// it has to restart the process on another server | |
// essentially a distributed version of forever | |
// no client/server relationship, all ring nodes are peers | |
var ring = require('ring').join('network guid') | |
, opts = { | |
distribution: { | |
min: 3, | |
max: 10 | |
} | |
}; | |
// - tell ring you want a process up no matter what | |
// - nodes on the ring keep eachother up to date | |
ring.start('my guid', opts, function(err, proc) { | |
// stdout is available over | |
// the network if needed | |
proc.stdout.on('data', function (data) { | |
process.stdout.write(data); | |
}); | |
ring.list(function (err, processes) { | |
// list all processes in | |
// the entire ring | |
console.log(processes); | |
}); | |
}); | |
// - all events come across the network | |
// - death can be due to a fault or failure | |
// to trigger a heartbeat event | |
ring.on('death', function (err, proc) { | |
// by default ring will try to restart on the same machine, | |
// if the proc cannot be brought up it will try another machine | |
// until this callback gets an 'err' that the entire ring is down | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment