mirror of
https://github.com/Hopiu/webapi-eca.git
synced 2026-03-16 22:10:31 +00:00
never commit in the middle of something... :)
This commit is contained in:
parent
7a51aed47b
commit
20748240c2
5 changed files with 53 additions and 56 deletions
|
|
@ -80,9 +80,20 @@ initRouting = ( port ) =>
|
|||
# - **`POST` to _"/user"_:** User requests are possible for all users with an account
|
||||
app.post '/usercommand', requestHandler.handleUserCommand
|
||||
try
|
||||
@server = app.listen port # inbound event channel
|
||||
catch e
|
||||
@log.error e, 'HL | Unable to listen...'
|
||||
@server = app.listen parseInt( port ) || 8125 # inbound event channel
|
||||
###
|
||||
Error handling of the express port listener requires special attention,
|
||||
thus we have to catch the error, which is issued if the port is already in use.
|
||||
###
|
||||
@server.on 'listening', () =>
|
||||
addr = @server.address()
|
||||
if addr.port is not port
|
||||
@shutDownSystem()
|
||||
@server.on 'error', ( err ) =>
|
||||
if err.errno is 'EADDRINUSE'
|
||||
@log.error err, 'HL | http-port already in use, shutting down!'
|
||||
@shutDownSystem()
|
||||
|
||||
|
||||
###
|
||||
Adds the shutdown handler to the admin commands.
|
||||
|
|
@ -90,7 +101,8 @@ Adds the shutdown handler to the admin commands.
|
|||
@param {function} fshutDown
|
||||
@public addShutdownHandler( *fShutDown* )
|
||||
###
|
||||
exports.addShutdownHandler = ( fShutDown ) ->
|
||||
exports.addShutdownHandler = ( fShutDown ) =>
|
||||
@shutDownSystem = fShutDown
|
||||
requestHandler.addShutdownHandler fShutDown
|
||||
|
||||
###
|
||||
|
|
@ -100,9 +112,6 @@ Shuts down the http listener.
|
|||
###
|
||||
exports.shutDown = () =>
|
||||
@log.warn 'HL | Shutting down HTTP listener'
|
||||
console.log 'apppp'
|
||||
console.log app
|
||||
@server.close()
|
||||
#TODO This is a bit brute force...
|
||||
#process.exit()
|
||||
try
|
||||
@server.close()
|
||||
|
||||
|
|
|
|||
|
|
@ -88,18 +88,6 @@ if argv.help
|
|||
process.exit()
|
||||
|
||||
###
|
||||
Error handling of the express port listener requires special attention,
|
||||
thus we have to catch the process error, which is issued if
|
||||
the port is already in use.
|
||||
###
|
||||
process.on 'uncaughtException', ( err ) =>
|
||||
switch err.errno
|
||||
when 'EADDRINUSE'
|
||||
@log.error err, 'RS | http-port already in use, shutting down!'
|
||||
shutDown()
|
||||
# else @log.error 'RS', err
|
||||
else throw err
|
||||
###
|
||||
This function is invoked right after the module is loaded and starts the server.
|
||||
|
||||
@private init()
|
||||
|
|
@ -146,6 +134,8 @@ init = =>
|
|||
@log.info 'RS | Initialzing engine'
|
||||
engine args
|
||||
@log.info 'RS | Initialzing http listener'
|
||||
# We give the HTTP listener the ability to shutdown the whole system
|
||||
http.addShutdownHandler shutDown
|
||||
http args
|
||||
|
||||
# > Distribute handlers between modules to link the application.
|
||||
|
|
@ -153,7 +143,6 @@ init = =>
|
|||
engine.addPersistence db
|
||||
@log.info 'RS | Passing handlers to http listener'
|
||||
#TODO engine pushEvent needs to go into redis queue
|
||||
http.addShutdownHandler shutDown
|
||||
#TODO loadAction and addRule will be removed
|
||||
#mm.addHandlers db, engine.loadActionModule, engine.addRule
|
||||
@log.info 'RS | Forking child process for the event poller'
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ HTTP Listener
|
|||
|
||||
|
||||
initRouting = function(port) {
|
||||
var e, sess_sec;
|
||||
var sess_sec;
|
||||
app.use(express.cookieParser());
|
||||
sess_sec = "149u*y8C:@kmN/520Gt\\v'+KFBnQ!\\r<>5X/xRI`sT<Iw";
|
||||
app.use(express.session({
|
||||
|
|
@ -65,11 +65,26 @@ HTTP Listener
|
|||
app.post('/logout', requestHandler.handleLogout);
|
||||
app.post('/usercommand', requestHandler.handleUserCommand);
|
||||
try {
|
||||
return _this.server = app.listen(port);
|
||||
} catch (_error) {
|
||||
e = _error;
|
||||
return _this.log.error(e, 'HL | Unable to listen...');
|
||||
}
|
||||
_this.server = app.listen(parseInt(port) || 8125);
|
||||
/*
|
||||
Error handling of the express port listener requires special attention,
|
||||
thus we have to catch the error, which is issued if the port is already in use.
|
||||
*/
|
||||
|
||||
_this.server.on('listening', function() {
|
||||
var addr;
|
||||
addr = _this.server.address();
|
||||
if (addr.port === !port) {
|
||||
return _this.shutDownSystem();
|
||||
}
|
||||
});
|
||||
return _this.server.on('error', function(err) {
|
||||
if (err.errno === 'EADDRINUSE') {
|
||||
_this.log.error(err, 'HL | http-port already in use, shutting down!');
|
||||
return _this.shutDownSystem();
|
||||
}
|
||||
});
|
||||
} catch (_error) {}
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
@ -81,6 +96,7 @@ HTTP Listener
|
|||
|
||||
|
||||
exports.addShutdownHandler = function(fShutDown) {
|
||||
_this.shutDownSystem = fShutDown;
|
||||
return requestHandler.addShutdownHandler(fShutDown);
|
||||
};
|
||||
|
||||
|
|
@ -93,9 +109,9 @@ HTTP Listener
|
|||
|
||||
exports.shutDown = function() {
|
||||
_this.log.warn('HL | Shutting down HTTP listener');
|
||||
console.log('apppp');
|
||||
console.log(app);
|
||||
return _this.server.close();
|
||||
try {
|
||||
return _this.server.close();
|
||||
} catch (_error) {}
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
|
|
|||
|
|
@ -89,23 +89,6 @@ WebAPI-ECA Engine
|
|||
process.exit();
|
||||
}
|
||||
|
||||
/*
|
||||
Error handling of the express port listener requires special attention,
|
||||
thus we have to catch the process error, which is issued if
|
||||
the port is already in use.
|
||||
*/
|
||||
|
||||
|
||||
process.on('uncaughtException', function(err) {
|
||||
switch (err.errno) {
|
||||
case 'EADDRINUSE':
|
||||
_this.log.error(err, 'RS | http-port already in use, shutting down!');
|
||||
return shutDown();
|
||||
default:
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
This function is invoked right after the module is loaded and starts the server.
|
||||
|
||||
|
|
@ -157,11 +140,11 @@ WebAPI-ECA Engine
|
|||
_this.log.info('RS | Initialzing engine');
|
||||
engine(args);
|
||||
_this.log.info('RS | Initialzing http listener');
|
||||
http.addShutdownHandler(shutDown);
|
||||
http(args);
|
||||
_this.log.info('RS | Passing handlers to engine');
|
||||
engine.addPersistence(db);
|
||||
_this.log.info('RS | Passing handlers to http listener');
|
||||
http.addShutdownHandler(shutDown);
|
||||
_this.log.info('RS | Forking child process for the event poller');
|
||||
cliArgs = [args.logconf['mode'], args.logconf['io-level'], args.logconf['file-level'], args.logconf['file-path'], args.logconf['nolog']];
|
||||
return poller = cp.fork(path.resolve(__dirname, 'event-poller'), cliArgs);
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ exports.testShutDown = ( test ) =>
|
|||
# Garbage collect eventually still running process
|
||||
fWaitForDeath = () ->
|
||||
if isRunning
|
||||
test.ok false, 'Engine didn\'t shut down!'
|
||||
test.ok false, '"testShutDown" Engine didn\'t shut down!'
|
||||
engine.kill()
|
||||
test.done()
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ exports.testKill = ( test ) =>
|
|||
|
||||
# Garbage collect eventually still running process
|
||||
fWaitForDeath = () ->
|
||||
test.ok engine.killed, 'Engine didn\'t shut down!'
|
||||
test.ok engine.killed, '"testKill" Engine didn\'t shut down!'
|
||||
test.done()
|
||||
|
||||
setTimeout fWaitForStartup, 1000
|
||||
|
|
@ -69,12 +69,12 @@ exports.testHttpPortAlreadyUsed = ( test ) =>
|
|||
isRunning = false
|
||||
test.done()
|
||||
|
||||
setTimeout fWaitForDeath, 3000
|
||||
setTimeout fWaitForDeath, 1000
|
||||
|
||||
# Garbage collect eventually still running process
|
||||
fWaitForDeath = () =>
|
||||
if isRunning
|
||||
test.ok false, 'Engine didn\'t shut down!'
|
||||
test.ok false, '"testHttpPortAlreadyUsed" Engine didn\'t shut down!'
|
||||
test.done()
|
||||
|
||||
@engine_one.kill()
|
||||
|
|
@ -87,7 +87,7 @@ exports.testHttpPortInvalid = ( test ) =>
|
|||
|
||||
isRunning = true
|
||||
pth = path.resolve 'js-coffee', 'webapi-eca'
|
||||
engine = cp.fork pth, ['-n', '-w', '-1'] # [ '-i' , 'warn' ]
|
||||
engine = cp.fork pth, ['-n', '-w', '0'] # [ '-i' , 'warn' ]
|
||||
engine.on 'exit', ( code, signal ) ->
|
||||
test.ok true, 'Engine stopped'
|
||||
isRunning = false
|
||||
|
|
@ -95,10 +95,10 @@ exports.testHttpPortInvalid = ( test ) =>
|
|||
|
||||
# Garbage collect eventually still running process
|
||||
fWaitForDeath = () =>
|
||||
engine.kill()
|
||||
if isRunning
|
||||
test.ok false, 'Engine didn\'t shut down!'
|
||||
test.ok false, '"testHttpPortInvalid" Engine didn\'t shut down!'
|
||||
test.done()
|
||||
|
||||
engine.kill()
|
||||
|
||||
setTimeout fWaitForDeath, 1000
|
||||
|
|
|
|||
Loading…
Reference in a new issue