Skip to content

Instantly share code, notes, and snippets.

@fengmk2
Last active August 29, 2015 14:01
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 fengmk2/301f5da8a56f7cc82e09 to your computer and use it in GitHub Desktop.
Save fengmk2/301f5da8a56f7cc82e09 to your computer and use it in GitHub Desktop.
cluster dir watcher
var cluster = require('cluster');
function watchdir(dir) {
var watcher = childprocess.fork('watcher.js', [dir]);
watcher.on('exit', function () {
// logger exit message
watcher = null;
// refork again
setTimeout(watchdir.bind(null, dir), 1000);
}).on('message', function (info) {
if (info.isFile) {
sendClusterMessage({action: 'watch-file', info: info});
}
});
}
watchdir(cmspath);
var wt = require('wt');
var dir = process.argv[2];
wt.watch(dir).on('file', function (info) {
process.send(info);
});
// cluster mode
process.on('message', function (msg) {
if (msg && msg.action === 'watch-file') {
reloadFile(msg.info.path);
}
});
@fengmk2
Copy link
Author

fengmk2 commented May 20, 2014

@dead-horse 大概这个思路

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment