Skip to content

Commit

Permalink
only one slack message per signal catch, #220
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Nov 1, 2024
1 parent 9c0f8a2 commit da2d17c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions js/server/QuickServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,21 @@ class QuickServer {
* Send a slack message when exiting unexpectedly to say that we exited.
*/
private wireUpMessageOnExit(): void {
let handledSignal = false;

// catching signals and do something before exit
[ 'SIGINT', 'SIGHUP', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT', 'SIGBUS', 'SIGFPE', 'SIGUSR1',
'SIGSEGV', 'SIGUSR2', 'SIGTERM', 'beforeExit', 'uncaughtException', 'unhandledRejection'
].forEach( sig => {
process.on( sig, ( error: Error ) => {
const message = `CTQ has caught ${sig} and will now exit. ${error}`;
winston.info( message );
this.slackMessage( message ).then( () => {
process.exit( 1 );
} ).catch( e => { throw e; } );
if ( !handledSignal ) {
handledSignal = true;
const message = `CTQ has caught ${sig} and will now exit. ${error}`;
winston.info( message );
this.slackMessage( message ).then( () => {
process.exit( 1 );
} ).catch( e => { throw e; } );
}
} );
} );
}
Expand Down

0 comments on commit da2d17c

Please sign in to comment.