converting to MP, just config in accessRights left
This commit is contained in:
+54
-15
@@ -75,19 +75,59 @@ const cfgh = new configHelper({
|
||||
localfile: './wssGatewayConfig.json',
|
||||
})
|
||||
|
||||
async function startRedis(wssGatewayConfig) {
|
||||
let REDIScnx = new RedisConnexion({
|
||||
debug: debug,
|
||||
config: wssGatewayConfig,
|
||||
});
|
||||
if(debug) console.log('Starting REDIS...');
|
||||
await REDIScnx.redisLogin();
|
||||
if(debug) console.log('REDIS Login OK');
|
||||
await REDIScnx.redisChansStart();
|
||||
if(debug) console.log('REDIS ChansStart OK');
|
||||
return (REDIScnx);
|
||||
}
|
||||
async function startAllRedis(wssGatewayConfig) {
|
||||
if (debug) console.log('Starting all Redis instances...')
|
||||
|
||||
//1. instantiate all & login all
|
||||
const redisConns = wssGatewayConfig.redis.map(cfg =>
|
||||
new RedisConnexion({ debug, config: cfg, redisId:cfg.redisId })
|
||||
)
|
||||
const loginResults = await Promise.allSettled(
|
||||
redisConns.map(async cnx => {
|
||||
cnx.redisLogin()
|
||||
return cnx.redisId
|
||||
})
|
||||
)
|
||||
|
||||
2. //make sure all connected before going any further
|
||||
const failedLogin = loginResults.filter(r => r.status !== 'fulfilled')
|
||||
if (failedLogin.length > 0) {
|
||||
console.error('Redis login failures:')
|
||||
failedLogin.forEach((r, i) => {
|
||||
const id = redisConns[i].redisId
|
||||
console.error(`chansStart failed for redis:[${id}] → ${r.reason}`)
|
||||
})
|
||||
throw new Error(
|
||||
`Redis login failed for ${failedLogin.length}/${redisConns.length} instances`
|
||||
)
|
||||
}
|
||||
|
||||
if (debug) console.log('All Redis logins OK')
|
||||
|
||||
// --- Phase 2: start channels for all (since all succeeded)
|
||||
const chanResults = await Promise.allSettled(
|
||||
redisConns.map(async cnx => {
|
||||
cnx.redisChansStart()
|
||||
return cnx.redisId
|
||||
})
|
||||
)
|
||||
|
||||
const failedChans = chanResults.filter(r => r.status !== 'fulfilled')
|
||||
if (failedChans.length > 0) {
|
||||
console.error('Redis chansStart failures:')
|
||||
failedChans.forEach((r, i) => {
|
||||
const id = redisConns[i].redisId
|
||||
console.error(`chansStart failed for redis:[${id}] → ${r.reason}`)
|
||||
})
|
||||
throw new Error(
|
||||
`Redis chansStart failed for ${failedChans.length}/${redisConns.length} instances`
|
||||
)
|
||||
}
|
||||
|
||||
if (debug) console.log('All Redis chansStart OK')
|
||||
|
||||
return redisConns
|
||||
}
|
||||
|
||||
cfgh.fetchConfig().then( async wssGatewayConfig => {
|
||||
|
||||
@@ -150,9 +190,8 @@ cfgh.fetchConfig().then( async wssGatewayConfig => {
|
||||
console.log(`WS${wssGatewayConfig.server.unsecure ? '': 'S'} server created for ${wssGatewayConfig.server.listenHost}:${wssGatewayConfig.server.listenPort}`)
|
||||
})
|
||||
|
||||
startRedis(wssGatewayConfig).then((rediscnx) => {
|
||||
if(debug) console.log('Redis started & logged in !');
|
||||
const wssSrv = new wssServer(cfgh, WSSServer, rediscnx, debug);
|
||||
startRedis(wssGatewayConfig).then((allRediscnx) => {
|
||||
const wssSrv = new wssServer(cfgh, WSSServer, allRediscnx, debug);
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user