fix initDatabase function by proper use of await in try catch (#2360)

* fix initDatabase function by proper use of await in try catch

* lint-fix

---------

Co-authored-by: Henry Heng <henryheng@flowiseai.com>
This commit is contained in:
Saurabh Gupta
2024-05-13 16:45:22 +05:30
committed by GitHub
parent ee9d3a33fa
commit 823cefb5c5
+25 -26
View File
@@ -43,40 +43,39 @@ export class App {
async initDatabase() { async initDatabase() {
// Initialize database // Initialize database
this.AppDataSource.initialize() try {
.then(async () => { await this.AppDataSource.initialize()
logger.info('📦 [server]: Data Source is initializing...') logger.info('📦 [server]: Data Source is initializing...')
// Run Migrations Scripts // Run Migrations Scripts
await this.AppDataSource.runMigrations({ transaction: 'each' }) await this.AppDataSource.runMigrations({ transaction: 'each' })
// Initialize nodes pool // Initialize nodes pool
this.nodesPool = new NodesPool() this.nodesPool = new NodesPool()
await this.nodesPool.initialize() await this.nodesPool.initialize()
// Initialize chatflow pool // Initialize chatflow pool
this.chatflowPool = new ChatflowPool() this.chatflowPool = new ChatflowPool()
// Initialize API keys // Initialize API keys
await getAPIKeys() await getAPIKeys()
// Initialize encryption key // Initialize encryption key
await getEncryptionKey() await getEncryptionKey()
// Initialize Rate Limit // Initialize Rate Limit
const AllChatFlow: IChatFlow[] = await getAllChatFlow() const AllChatFlow: IChatFlow[] = await getAllChatFlow()
await initializeRateLimiter(AllChatFlow) await initializeRateLimiter(AllChatFlow)
// Initialize cache pool // Initialize cache pool
this.cachePool = new CachePool() this.cachePool = new CachePool()
// Initialize telemetry // Initialize telemetry
this.telemetry = new Telemetry() this.telemetry = new Telemetry()
logger.info('📦 [server]: Data Source has been initialized!') logger.info('📦 [server]: Data Source has been initialized!')
}) } catch (error) {
.catch((err) => { logger.error('❌ [server]: Error during Data Source initialization:', error)
logger.error('❌ [server]: Error during Data Source initialization:', err) }
})
} }
async config(socketIO?: Server) { async config(socketIO?: Server) {