close db connection in server HMR

This commit is contained in:
lesion 2022-05-25 10:53:39 +02:00
parent 601c3f7dc8
commit 5125c51ea8
No known key found for this signature in database
GPG key ID: 352918250B012177
2 changed files with 33 additions and 31 deletions

View file

@ -1,15 +1,29 @@
module.exports = function () {
const config = require('../server/config')
config.load()
const initialize = {
// close connections/port/unix socket
async shutdown (exit = true) {
const log = require('../server/log')
const TaskManager = require('../server/taskManager').TaskManager
if (TaskManager) { TaskManager.stop() }
log.info('Closing DB')
const sequelize = require('../server/api/models')
await sequelize.close()
process.off('SIGTERM', initialize.shutdown)
process.off('SIGINT', initialize.shutdown)
if (exit) {
process.exit()
}
},
async start () {
const log = require('../server/log')
const settingsController = require('./api/controller/settings')
const db = require('./api/models/index')
const dayjs = require('dayjs')
const timezone = require('dayjs/plugin/timezone')
dayjs.extend(timezone)
async function start (nuxt) {
config.load()
if (config.status == 'READY') {
await db.initialize()
} else {
@ -41,23 +55,11 @@ module.exports = function () {
TaskManager = require('../server/taskManager').TaskManager
TaskManager.start()
}
log.info(`Listen on ${config.server.host}:${config.server.port}`)
// close connections/port/unix socket
async function shutdown () {
if (TaskManager) { TaskManager.stop() }
log.info('Closing DB')
const sequelize = require('../server/api/models')
await sequelize.close()
process.off('SIGTERM', shutdown)
process.off('SIGINT', shutdown)
if (nuxt) {
nuxt.close()
process.on('SIGTERM', initialize.shutdown)
process.on('SIGINT', initialize.shutdown)
}
process.exit()
}
process.on('SIGTERM', shutdown)
process.on('SIGINT', shutdown)
}
return start(this.nuxt)
}
module.exports = initialize

View file

@ -83,7 +83,7 @@ module.exports = {
load () {
console.error('dentro load !')
},
unload: initialize.shutdown
unload: () => initialize.shutdown(false)
// async unload () {
// const db = require('./api/models/index')
// await db.close()