Skip to content

Instantly share code, notes, and snippets.

@daGrevis
Created March 6, 2019 22:24
Show Gist options
  • Select an option

  • Save daGrevis/9e5682dfd65bd94b40f33d176bf5362a to your computer and use it in GitHub Desktop.

Select an option

Save daGrevis/9e5682dfd65bd94b40f33d176bf5362a to your computer and use it in GitHub Desktop.
process.on('SIGTERM', async () => {
logger.info(`Received SIGTERM, quitting connections...`)
const state = store.getState()
_.forEach(state.ircClients, ircClient => {
ircClient.quit()
})
await pollUntil(async () => {
const state = store.getState()
const isQueueEmpty =
eventQueue.getQueueLength() === 0 && eventQueue.getPendingLength() === 0
const didEveryoneQuit = _.every(
state.ircClients,
(ircClient, connectionId) => !state.isIrcClientConnected[connectionId],
)
if (!isQueueEmpty || !didEveryoneQuit) {
throw Error('Not quiting just yet!')
}
})
// Wait a second more just in case.
setTimeout(() => {
logger.info(`Connections quit, exiting...`)
process.exit()
}, 1000)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment