Skip to content

Commit

Permalink
[fix] Small fixes found from some upstream integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Apr 29, 2011
1 parent 9788748 commit 3112380
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/forever/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var Monitor = exports.Monitor = function (script, options) {
this.forever = options.forever || false;
this.command = options.command || 'node';
this.sourceDir = options.sourceDir;
this.minUptime = options.minUptime || 2000;
this.minUptime = typeof options.minUptime !== 'number' ? 2000 : options.minUptime;
this.options = options.options || [];
this.spawnWith = options.spawnWith || null;
this.uid = options.uid || forever.randomString(24);
Expand Down Expand Up @@ -100,15 +100,15 @@ Monitor.prototype.start = function (restart) {
this.child = child;
this.running = true;

this.once('save', function () {
self.emit(restart ? 'restart' : 'start', self);
this.once('save', function (file, data) {
self.emit(restart ? 'restart' : 'start', self, file, data);
});

this.save();

// Hook all stream data and process it
function listenTo (stream) {
child[stream].on('data', function ldata (data) {
function ldata (data) {
if (!self.silent && !self[stream]) {
//
// If we haven't been silenced, and we don't have a file stream
Expand All @@ -124,7 +124,9 @@ Monitor.prototype.start = function (restart) {
}

self.emit(stream, data);
});
}

child[stream].on('data', ldata);

child.on('exit', function () {
child[stream].removeListener('data', ldata);
Expand All @@ -138,9 +140,9 @@ Monitor.prototype.start = function (restart) {
child.on('exit', function (code) {
var spinning = Date.now() - self.ctime < self.minUptime;
self.warn('Forever detected script exited with code: ' + code);
self.times++;


if ((self.forever || self.times < self.max) && !self.forceStop && !spinning) {
self.times++;
process.nextTick(function () {
self.warn('Forever restarting script for ' + self.times + ' time');
self.start(true);
Expand Down

0 comments on commit 3112380

Please sign in to comment.