fix: Improved how Redis works for instances

This commit is contained in:
Davidson Gomes
2023-07-04 12:38:29 -03:00
parent 8cb431ad40
commit c4f39ab85c
16 changed files with 65 additions and 55 deletions

View File

@@ -5,10 +5,16 @@ import { Logger } from '../config/logger.config';
const logger = new Logger('Db Connection');
const db = configService.get<Database>('DATABASE');
export const dbserver = db.ENABLED
? mongoose.createConnection(db.CONNECTION.URI, {
export const dbserver = (() => {
if (db.ENABLED) {
const dbs = mongoose.createConnection(db.CONNECTION.URI, {
dbName: db.CONNECTION.DB_PREFIX_NAME + '-whatsapp-api',
})
: null;
});
logger.info('ON - dbName: ' + dbs['$dbName']);
process.on('beforeExit', () => {
dbserver.destroy(true, (error) => logger.error(error));
});
db.ENABLED ? logger.info('ON - dbName: ' + dbserver['$dbName']) : null;
return dbs;
}
})();