@@ -22,11 +22,13 @@ var sys = require('sys'),
22
22
//
23
23
var Monitor = exports . Monitor = function ( script , options ) {
24
24
events . EventEmitter . call ( this ) ;
25
-
25
+
26
+ options = options || { } ;
26
27
this . silent = options . silent || false ;
27
28
this . forever = options . forever || false ;
28
29
this . command = options . command || 'node' ;
29
30
this . sourceDir = options . sourceDir ;
31
+ this . minUptime = options . minUptime || 2000 ;
30
32
this . options = options . options || [ ] ;
31
33
this . spawnWith = options . spawnWith || null ;
32
34
this . uid = options . uid || forever . randomString ( 24 ) ;
@@ -126,10 +128,11 @@ Monitor.prototype.start = function (restart) {
126
128
listenTo ( 'stderr' ) ;
127
129
128
130
child . on ( 'exit' , function ( code ) {
131
+ var spinning = Date . now ( ) - self . ctime < self . minUptime ;
129
132
self . error ( 'Forever detected script exited with code: ' + code ) ;
130
133
self . times ++ ;
131
134
132
- if ( ( self . forever || self . times < self . max ) && ! self . forceStop ) {
135
+ if ( ( self . forever || self . times < self . max ) && ! self . forceStop && ! spinning ) {
133
136
process . nextTick ( function ( ) {
134
137
self . warn ( 'Forever restarting script for ' + self . times + ' time' ) ;
135
138
self . start ( true ) ;
@@ -143,7 +146,7 @@ Monitor.prototype.start = function (restart) {
143
146
// If had to write to an stderr file, close it
144
147
if ( self . stderr ) self . stderr . end ( ) ;
145
148
146
- self . emit ( 'exit' , self ) ;
149
+ self . emit ( 'exit' , self , spinning ) ;
147
150
}
148
151
} ) ;
149
152
0 commit comments