feat: handle event propagation via DB (HA)

This commit is contained in:
NGPixel
2020-02-02 21:55:29 -05:00
committed by Nicolas Giard
parent 8aba5305d8
commit 7cd5721ca1
9 changed files with 145 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
const _ = require('lodash')
const EventEmitter = require('events')
const EventEmitter = require('eventemitter2').EventEmitter2
/* global WIKI */
@@ -37,6 +37,7 @@ module.exports = {
WIKI.servers = require('./servers')
WIKI.sideloader = require('./sideloader').init()
WIKI.events = new EventEmitter()
await WIKI.models.subscribeToNotifications()
} catch (err) {
WIKI.logger.error(err)
process.exit(1)
@@ -91,5 +92,21 @@ module.exports = {
WIKI.logger.warn(err)
WIKI.telemetry.sendError(err)
})
},
/**
* Graceful shutdown
*/
async shutdown () {
if (WIKI.models) {
await WIKI.models.unsubscribeToNotifications()
await WIKI.models.knex.client.pool.destroy()
await WIKI.models.knex.destroy()
}
if (WIKI.scheduler) {
WIKI.scheduler.stop()
}
if (WIKI.servers) {
await WIKI.servers.stopServers()
}
}
}