Created
March 6, 2019 22:24
-
-
Save daGrevis/9e5682dfd65bd94b40f33d176bf5362a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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