sort app.ts

moved handleTermSignals to utils.ts

Signed-off-by: Philip Molares <philip.molares@udo.edu>
Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
Philip Molares 2020-04-18 19:37:47 +02:00 committed by David Mehren
parent 9d17f6a7f4
commit 94c3857d49
No known key found for this signature in database
GPG key ID: 6017AF117F9756CB
2 changed files with 127 additions and 118 deletions

View file

@ -1,4 +1,9 @@
import { Sequelize } from 'sequelize-typescript'
import { logger } from './logger'
import { realtime } from './realtime'
import { config } from './config'
import fs from 'fs'
import { Revision } from './models'
export function isSQLite (sequelize: Sequelize): boolean {
return sequelize.options.dialect === 'sqlite'
@ -49,3 +54,35 @@ export function processData (data, _default, process?) {
}
}
}
export function handleTermSignals (io): void {
logger.info('CodiMD has been killed by signal, try to exit gracefully...')
realtime.maintenance = true
// disconnect all socket.io clients
Object.keys(io.sockets.sockets).forEach(function (key) {
const socket = io.sockets.sockets[key]
// notify client server going into maintenance status
socket.emit('maintenance')
setTimeout(function () {
socket.disconnect(true)
}, 0)
})
if (config.path) {
// ToDo: add a proper error handler
// eslint-disable-next-line @typescript-eslint/no-empty-function
fs.unlink(config.path, (_) => {})
}
const checkCleanTimer = setInterval(function () {
if (realtime.isReady()) {
Revision.checkAllNotesRevision(function (err, notes) {
if (err) {
return logger.error(err)
}
if (!notes || notes.length <= 0) {
clearInterval(checkCleanTimer)
return process.exit(0)
}
})
}
}, 100)
}