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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 25 additions and 26 deletions

View File

@ -43,40 +43,39 @@ export class App {
async initDatabase() {
// Initialize database
this.AppDataSource.initialize()
.then(async () => {
logger.info('📦 [server]: Data Source is initializing...')
try {
await this.AppDataSource.initialize()
logger.info('📦 [server]: Data Source is initializing...')
// Run Migrations Scripts
await this.AppDataSource.runMigrations({ transaction: 'each' })
// Run Migrations Scripts
await this.AppDataSource.runMigrations({ transaction: 'each' })
// Initialize nodes pool
this.nodesPool = new NodesPool()
await this.nodesPool.initialize()
// Initialize nodes pool
this.nodesPool = new NodesPool()
await this.nodesPool.initialize()
// Initialize chatflow pool
this.chatflowPool = new ChatflowPool()
// Initialize chatflow pool
this.chatflowPool = new ChatflowPool()
// Initialize API keys
await getAPIKeys()
// Initialize API keys
await getAPIKeys()
// Initialize encryption key
await getEncryptionKey()
// Initialize encryption key
await getEncryptionKey()
// Initialize Rate Limit
const AllChatFlow: IChatFlow[] = await getAllChatFlow()
await initializeRateLimiter(AllChatFlow)
// Initialize Rate Limit
const AllChatFlow: IChatFlow[] = await getAllChatFlow()
await initializeRateLimiter(AllChatFlow)
// Initialize cache pool
this.cachePool = new CachePool()
// Initialize cache pool
this.cachePool = new CachePool()
// Initialize telemetry
this.telemetry = new Telemetry()
logger.info('📦 [server]: Data Source has been initialized!')
})
.catch((err) => {
logger.error('❌ [server]: Error during Data Source initialization:', err)
})
// Initialize telemetry
this.telemetry = new Telemetry()
logger.info('📦 [server]: Data Source has been initialized!')
} catch (error) {
logger.error('❌ [server]: Error during Data Source initialization:', error)
}
}
async config(socketIO?: Server) {