mirror of
https://github.com/Hopiu/webapi-eca.git
synced 2026-03-16 22:10:31 +00:00
Database select added for several parallel systems on the same redis instance
This commit is contained in:
parent
d7c09e2e2e
commit
ff859d6d7c
5 changed files with 31 additions and 0 deletions
|
|
@ -63,6 +63,9 @@ exports.initPort = ( port ) =>
|
||||||
exports.eventPollers.setDB @db
|
exports.eventPollers.setDB @db
|
||||||
exports.actionInvokers.setDB @db
|
exports.actionInvokers.setDB @db
|
||||||
|
|
||||||
|
exports.selectDatabase = ( id ) =>
|
||||||
|
@db.select id
|
||||||
|
|
||||||
###
|
###
|
||||||
Checks whether the db is connected and passes either an error on failure after
|
Checks whether the db is connected and passes either an error on failure after
|
||||||
ten attempts within five seconds, or nothing on success to the callback(err).
|
ten attempts within five seconds, or nothing on success to the callback(err).
|
||||||
|
|
|
||||||
|
|
@ -57,35 +57,48 @@ opt =
|
||||||
'h':
|
'h':
|
||||||
alias : 'help',
|
alias : 'help',
|
||||||
describe: 'Display this'
|
describe: 'Display this'
|
||||||
|
|
||||||
# `-c`, `--config-path`: Specify a path to a custom configuration file, other than "config/config.json"
|
# `-c`, `--config-path`: Specify a path to a custom configuration file, other than "config/config.json"
|
||||||
'c':
|
'c':
|
||||||
alias : 'config-path',
|
alias : 'config-path',
|
||||||
describe: 'Specify a path to a custom configuration file, other than "config/config.json"'
|
describe: 'Specify a path to a custom configuration file, other than "config/config.json"'
|
||||||
|
|
||||||
# `-w`, `--http-port`: Specify a HTTP port for the web server
|
# `-w`, `--http-port`: Specify a HTTP port for the web server
|
||||||
'w':
|
'w':
|
||||||
alias : 'http-port',
|
alias : 'http-port',
|
||||||
describe: 'Specify a HTTP port for the web server'
|
describe: 'Specify a HTTP port for the web server'
|
||||||
|
|
||||||
# `-d`, `--db-port`: Specify a port for the redis DB
|
# `-d`, `--db-port`: Specify a port for the redis DB
|
||||||
'd':
|
'd':
|
||||||
alias : 'db-port',
|
alias : 'db-port',
|
||||||
describe: 'Specify a port for the redis DB'
|
describe: 'Specify a port for the redis DB'
|
||||||
|
|
||||||
|
# `-s`, `--db-select`: Specify a database
|
||||||
|
's':
|
||||||
|
alias : 'db-select',
|
||||||
|
describe: 'Specify a database identifier'
|
||||||
|
|
||||||
# `-m`, `--log-mode`: Specify a log mode: [development|productive]
|
# `-m`, `--log-mode`: Specify a log mode: [development|productive]
|
||||||
'm':
|
'm':
|
||||||
alias : 'log-mode',
|
alias : 'log-mode',
|
||||||
describe: 'Specify a log mode: [development|productive]'
|
describe: 'Specify a log mode: [development|productive]'
|
||||||
|
|
||||||
# `-i`, `--log-io-level`: Specify the log level for the I/O. in development expensive origin
|
# `-i`, `--log-io-level`: Specify the log level for the I/O. in development expensive origin
|
||||||
# lookups are made and added to the log entries
|
# lookups are made and added to the log entries
|
||||||
'i':
|
'i':
|
||||||
alias : 'log-io-level',
|
alias : 'log-io-level',
|
||||||
describe: 'Specify the log level for the I/O'
|
describe: 'Specify the log level for the I/O'
|
||||||
|
|
||||||
# `-f`, `--log-file-level`: Specify the log level for the log file
|
# `-f`, `--log-file-level`: Specify the log level for the log file
|
||||||
'f':
|
'f':
|
||||||
alias : 'log-file-level',
|
alias : 'log-file-level',
|
||||||
describe: 'Specify the log level for the log file'
|
describe: 'Specify the log level for the log file'
|
||||||
|
|
||||||
# `-p`, `--log-file-path`: Specify the path to the log file within the "logs" folder
|
# `-p`, `--log-file-path`: Specify the path to the log file within the "logs" folder
|
||||||
'p':
|
'p':
|
||||||
alias : 'log-file-path',
|
alias : 'log-file-path',
|
||||||
describe: 'Specify the path to the log file within the "logs" folder'
|
describe: 'Specify the path to the log file within the "logs" folder'
|
||||||
|
|
||||||
# `-n`, `--nolog`: Set this true if no output shall be generated
|
# `-n`, `--nolog`: Set this true if no output shall be generated
|
||||||
'n':
|
'n':
|
||||||
alias : 'nolog',
|
alias : 'nolog',
|
||||||
|
|
@ -133,6 +146,7 @@ init = =>
|
||||||
# > Fetch the `http-port` argument
|
# > Fetch the `http-port` argument
|
||||||
args[ 'http-port' ] = parseInt argv.w || conf.getHttpPort()
|
args[ 'http-port' ] = parseInt argv.w || conf.getHttpPort()
|
||||||
args[ 'db-port' ] = parseInt argv.d || conf.getDbPort()
|
args[ 'db-port' ] = parseInt argv.d || conf.getDbPort()
|
||||||
|
args[ 'db-select' ] = parseInt argv.s || conf.fetchProp 'db-select'
|
||||||
|
|
||||||
#FIXME this has to come from user input for security reasons:
|
#FIXME this has to come from user input for security reasons:
|
||||||
args[ 'keygen' ] = conf.getKeygenPassphrase()
|
args[ 'keygen' ] = conf.getKeygenPassphrase()
|
||||||
|
|
@ -146,6 +160,7 @@ init = =>
|
||||||
#TODO eventually we shouldn't let each module load its own persistence
|
#TODO eventually we shouldn't let each module load its own persistence
|
||||||
#module, but hand this one through them via the args...
|
#module, but hand this one through them via the args...
|
||||||
db.isConnected ( err ) =>
|
db.isConnected ( err ) =>
|
||||||
|
db.selectDatabase parseInt( args[ 'db-select' ] ) || 0
|
||||||
if err
|
if err
|
||||||
@log.error 'RS | No DB connection, shutting down system!'
|
@log.error 'RS | No DB connection, shutting down system!'
|
||||||
shutDown()
|
shutDown()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"http-port": 8125,
|
"http-port": 8125,
|
||||||
"db-port": 6379,
|
"db-port": 6379,
|
||||||
|
"db-select": 0,
|
||||||
"log": {
|
"log": {
|
||||||
"nolog": "false",
|
"nolog": "false",
|
||||||
"mode": "development",
|
"mode": "development",
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,12 @@ Persistence
|
||||||
};
|
};
|
||||||
})(this);
|
})(this);
|
||||||
|
|
||||||
|
exports.selectDatabase = (function(_this) {
|
||||||
|
return function(id) {
|
||||||
|
return _this.db.select(id);
|
||||||
|
};
|
||||||
|
})(this);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Checks whether the db is connected and passes either an error on failure after
|
Checks whether the db is connected and passes either an error on failure after
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,10 @@ WebAPI-ECA Engine
|
||||||
alias: 'db-port',
|
alias: 'db-port',
|
||||||
describe: 'Specify a port for the redis DB'
|
describe: 'Specify a port for the redis DB'
|
||||||
},
|
},
|
||||||
|
's': {
|
||||||
|
alias: 'db-select',
|
||||||
|
describe: 'Specify a database identifier'
|
||||||
|
},
|
||||||
'm': {
|
'm': {
|
||||||
alias: 'log-mode',
|
alias: 'log-mode',
|
||||||
describe: 'Specify a log mode: [development|productive]'
|
describe: 'Specify a log mode: [development|productive]'
|
||||||
|
|
@ -147,6 +151,7 @@ WebAPI-ECA Engine
|
||||||
};
|
};
|
||||||
args['http-port'] = parseInt(argv.w || conf.getHttpPort());
|
args['http-port'] = parseInt(argv.w || conf.getHttpPort());
|
||||||
args['db-port'] = parseInt(argv.d || conf.getDbPort());
|
args['db-port'] = parseInt(argv.d || conf.getDbPort());
|
||||||
|
args['db-select'] = parseInt(argv.s || conf.fetchProp('db-select'));
|
||||||
args['keygen'] = conf.getKeygenPassphrase();
|
args['keygen'] = conf.getKeygenPassphrase();
|
||||||
args['webhooks'] = conf.fetchProp('webhooks');
|
args['webhooks'] = conf.fetchProp('webhooks');
|
||||||
encryption(args);
|
encryption(args);
|
||||||
|
|
@ -154,6 +159,7 @@ WebAPI-ECA Engine
|
||||||
db(args);
|
db(args);
|
||||||
return db.isConnected(function(err) {
|
return db.isConnected(function(err) {
|
||||||
var cliArgs, poller;
|
var cliArgs, poller;
|
||||||
|
db.selectDatabase(parseInt(args['db-select']) || 0);
|
||||||
if (err) {
|
if (err) {
|
||||||
_this.log.error('RS | No DB connection, shutting down system!');
|
_this.log.error('RS | No DB connection, shutting down system!');
|
||||||
return shutDown();
|
return shutDown();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue