mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 09:45:37 -04:00
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:
parent
9d17f6a7f4
commit
94c3857d49
2 changed files with 127 additions and 118 deletions
37
lib/utils.ts
37
lib/utils.ts
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue