Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[dist] Prototype finished

  • Loading branch information...
commit 88ceb276e38b1c7824d7a55feb16c913fc5e3eb1 1 parent ed43a5e
@alejandro alejandro authored
Showing with 27 additions and 32 deletions.
  1. +8 −6 examples/child.js
  2. +9 −11 examples/master.js
  3. +10 −15 lib/watcher.js
View
14 examples/child.js
@@ -1,12 +1,14 @@
-var watcher = (new (require('../lib/watcher'))({
+(new (require('../lib/watcher'))({
host:'localhost'
-}))
-
-
-watcher.emitter({
- maxMemory:25 //25mb
+})).emitter({
+ maxMemory:25, //25mb,
+ sizeSpace:25,
+ checkSpace:true
})
+require('http').createServer(function(req,res){
+ res.end('pl')
+}).listen(9011)
/*
View
20 examples/master.js
@@ -1,16 +1,14 @@
var bolt = require('bolt');
-var restart = require('lib/app').restart;
+
var mesh = new bolt.Node({
delimiter:'::',
- host: options.host || 'localhost',
- port: options.port || 6379,
- auth: options.auth || ''
+ host: 'localhost',
+ port: 6379,
+ silent:true
});
+mesh.start()
mesh.on('nodester::dieing',function(app){
- var proxytable =require('/path/to/proxy/table.json')
- for (subdomain in proxytable){
- if (proxytable[subdomain]===app.port){
- restart(proxytable[subdomain]);
- }
- }
-})
+ console.log('')
+ console.log(app.PID)
+ console.log(app.code)
+})
View
25 lib/watcher.js
@@ -10,7 +10,7 @@ var exec = require('child_process').exec;
var bolt = require('bolt');
var events = require("events");
var utils = require('util');
-
+kue = true
var Watcher = function (cfg) {
console.log('App in audit mode by Watcher...')
this.mesh = new bolt.Node({
@@ -20,7 +20,9 @@ var Watcher = function (cfg) {
auth: cfg.auth || '',
silent:true
});
+ var mesh = this.mesh;
events.EventEmitter.call(this);
+
};
utils.inherits(Watcher, events.EventEmitter);
@@ -29,16 +31,17 @@ Watcher.prototype.emitter = function(options){
var mesh = this.mesh;
mesh.start()
options = options || {};
- process.maxMemory = options.maxMemory ? options.maxMemory*1024*1024:-1;
+ process.maxMemory = options.maxMemory ? options.maxMemory*1024:-1;
process.thisBorn = Date.now();
process.maxLifeTime = options.maxLifeTime;
options.interval = options.interval || 200;
process.checkSpace = options.checkSpace || true;
- process.maxSpace = options.sizeSpace || 25000;
+ process.maxSpace = options.sizeSpace*1024 || 25000;
function smash() {
if (options.maxMemory != -1) {
var memory = process.memoryUsage().rss;
- if (options.maxMemory>=memory) {
+ if (options.maxMemory>=memory && kue) {
+ kue = false
kill('You reached '+options.maxMemory+'Mbs',101);
}
}
@@ -51,7 +54,8 @@ Watcher.prototype.emitter = function(options){
});
// Evil eval is evil, too lazy right now to make the map|forEach|filter function
var totalSize =eval(size.join('+'));
- if (totalSize>=options.sizeSpace){
+ if (totalSize>=process.maxSpace && kue){
+ kue = false
kill('There is no space left in for this app, max allowed: '+(options.sizeSpace/1024),911)
}
}
@@ -66,7 +70,7 @@ Watcher.prototype.emitter = function(options){
// Let's have some time to emit the deing event
setTimeout(function(){
process.exit(0);
- },500)
+ },200)
}
mesh.on('nodester::kill', function(PID){
if (PID === process.pid){
@@ -76,15 +80,6 @@ Watcher.prototype.emitter = function(options){
});
setInterval(smash, options.interval);
}
-Watcher.prototype.listener = function(){
- var mesh = this.mesh;
- mesh.on('nodester::dieing', function(data){
- this.emit('killProcess',data);
- });
-}
-Watcher.prototype.listener.prototype.kill = function(PID){
- this.mesh.emit('nodester::kill',PID);
-}
Object.defineProperty(Watcher, 'codes', {
get: function(){
Please sign in to comment.
Something went wrong with that request. Please try again.