1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 10:19:30 +02:00

Don't listen to 'end' on proxy server.

This commit is contained in:
Simo Kinnunen 2014-04-04 20:08:51 +09:00
parent 45f7db1728
commit e0b4b3b40f
2 changed files with 22 additions and 10 deletions

View file

@ -76,7 +76,9 @@ module.exports = syrup.serial()
var resolver = Promise.defer() var resolver = Promise.defer()
function resolve() { function resolve() {
lifecycle.share('Proxy server', proxyServer) lifecycle.share('Proxy server', proxyServer, {
end: false
})
resolver.resolve() resolver.resolve()
} }

View file

@ -2,6 +2,7 @@ var Promise = require('bluebird')
var logger = require('./logger') var logger = require('./logger')
var log = logger.createLogger('util:lifecycle') var log = logger.createLogger('util:lifecycle')
var _ = require('lodash')
function Lifecycle() { function Lifecycle() {
this.observers = [] this.observers = []
@ -9,16 +10,25 @@ function Lifecycle() {
process.on('SIGTERM', this.graceful.bind(this)) process.on('SIGTERM', this.graceful.bind(this))
} }
Lifecycle.prototype.share = function(name, emitter) { Lifecycle.prototype.share = function(name, emitter, options) {
emitter.on('end', function() { _.defaults(options, {
log.fatal('%s ended; we shall share its fate', name) end: true
this.fatal() , error: true
}.bind(this)) })
emitter.on('error', function(err) { if (options.end) {
log.fatal('%s had an error', name, err.stack) emitter.on('end', function() {
this.fatal() log.fatal('%s ended; we shall share its fate', name)
}.bind(this)) this.fatal()
}.bind(this))
}
if (options.error) {
emitter.on('error', function(err) {
log.fatal('%s had an error', name, err.stack)
this.fatal()
}.bind(this))
}
return emitter return emitter
} }