exit
function is not working as it should.
It should be registering everything inside logger
function.
Instead, only console text pop-ups.
Even everything wrapped in server.close
is not working at all.
What's the reason behind this?
import { MongoRepository } from '@repositories/index'
import { container } from '@container/index'
import types from '@inversifyTypes/types'
import logger from '@logging/logger'
import { Server } from 'http'
const processHandler = (server: Server): void => {
const exit = (signal: string): void => {
console.log(`Received signal ${signal}. Closing resources...`)
logger.info(`Received signal ${signal}. Closing resources...`)
server.close(async () => {
console.log('Closing MongoDB connection...')
logger.info('Closing MongoDB connection...')
const mongoRepository = container.get<MongoRepository>(types.MongoRepository)
await mongoRepository.disconnect()
console.log('MongoDB connection closed successfully')
logger.info('MongoDB connection closed successfully')
process.exit(0)
})
}
// Handle SIGINT (Ctrl+C in the terminal)
process.on('SIGINT', () => exit('SIGINT'))
// Handle SIGTERM (termination signal sent)
process.on('SIGTERM', () => exit('SIGTERM'))
// Handle uncaught exceptions
process.on('uncaughtException', (error) => {
logger.error({ error }, 'Uncaught exception detected')
exit('uncaughtException')
})
// Handle unhandled promise rejections
process.on('unhandledRejection', (reason, promise) => {
logger.error({ promise, reason }, 'Unhandled promise rejection detected')
exit('unhandledRejection')
})
}
export default processHandler
CMD printing
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745577035a4634027.html
评论列表(0条)