Last active
August 29, 2015 14:01
-
-
Save fengmk2/301f5da8a56f7cc82e09 to your computer and use it in GitHub Desktop.
cluster dir watcher
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
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); |
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
var wt = require('wt'); | |
var dir = process.argv[2]; | |
wt.watch(dir).on('file', function (info) { | |
process.send(info); | |
}); |
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
// cluster mode | |
process.on('message', function (msg) { | |
if (msg && msg.action === 'watch-file') { | |
reloadFile(msg.info.path); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@dead-horse 大概这个思路