function attachGracefulShutdownHandlers() {
  ['SIGTERM', 'SIGINT', 'unhandledRejection', 'uncaughtException'].forEach((eventName) => {
    handlersByEventName[eventName] = process.listeners(eventName);
    process.removeAllListeners(eventName);
    process.on(eventName, async eventData => {
      const isAnUnhandledError = !eventName.startsWith('SIG');
      if (isAnUnhandledError) {
        console.log(`An ${eventName} occurred: ${eventData}`);
      }
      await shutDownGracefully({ eventName, cause: eventData });
      if (isAnUnhandledError) { // trigger the Flex SDK graceful shutdown manually
        handlersByEventName.SIGINT.forEach(handler => handler('SIGINT'));
      }
    });
  });
}
/**
 * Flex SDK attaches graceful shutdown handlers which we want to run, so the Flex service itself uninitializes
 * and stops accepting incoming requests, but we want to uninitialize our long-running (Kafka) processing logic before that,
 * so that Flex SDK doesn't make the process exit before we are done.
 * It's important to stop accepting new processing tasks at the point of long-running task uninitialization.
 * We have planned improvements on the graceful shutdown front for long-running tasks, but this is the current state.
 */
Flex SDK attaches graceful shutdown handlers which we want to run, so the Flex service itself uninitializes
and stops accepting incoming requests, but we want to uninitialize our long-running (Kafka) processing logic before that,
so that Flex SDK doesn't make the process exit before we are done.
It's important to stop accepting new processing tasks at the point of long-running task uninitialization.
We have planned improvements on the graceful shutdown front for long-running tasks, but this is the current state.
Flex SDK attaches graceful shutdown handlers which we want to run so the Flex service itself uninitializes and stops accepting incoming requests but we want to uninitialize our long - running ( Kafka ) processing logic before that so that Flex SDK doesn ' t make the process exit before we are done . It ' s important to stop accepting new processing tasks at the point of long - running task uninitialization . We have planned improvements on the graceful shutdown front for long - running tasks but this is the current state .
function attachGracefulShutdownHandlers() {
  ['SIGTERM', 'SIGINT', 'unhandledRejection', 'uncaughtException'].forEach((eventName) => {
    handlersByEventName[eventName] = process.listeners(eventName);
    process.removeAllListeners(eventName);
    process.on(eventName, async eventData => {
      const isAnUnhandledError = !eventName.startsWith('SIG');
      if (isAnUnhandledError) {
        console.log(`An ${eventName} occurred: ${eventData}`);
      }
      await shutDownGracefully({ eventName, cause: eventData });
      if (isAnUnhandledError) { 
        handlersByEventName.SIGINT.forEach(handler => handler('SIGINT'));
      }
    });
  });
}
function attachGracefulShutdownHandlers ( ) { [ 'SIGTERM' , 'SIGINT' , 'unhandledRejection' , 'uncaughtException' ] . forEach ( ( eventName ) => { handlersByEventName [ eventName ] = process . listeners ( eventName ) ; process . removeAllListeners ( eventName ) ; process . on ( eventName , async eventData => { const isAnUnhandledError = ! eventName . startsWith ( 'SIG' ) ; if ( isAnUnhandledError ) { console . log ( ` ${ eventName } ${ eventData } ` ) ; } await shutDownGracefully ( { eventName , cause : eventData } ) ; if ( isAnUnhandledError ) { handlersByEventName . SIGINT . forEach ( handler => handler ( 'SIGINT' ) ) ; } } ) ; } ) ; }
Flex SDK attaches graceful shutdown handlers which we want to run, so the Flex service itself uninitializes
 and stops accepting incoming requests, but we want to uninitialize our long-running (Kafka) processing logic before that,
 so that Flex SDK doesn't make the process exit before we are done.
Flex SDK attaches graceful shutdown handlers which we want to run so the Flex service itself uninitializes and stops accepting incoming requests but we want to uninitialize our long - running ( Kafka ) processing logic before that so that Flex SDK doesn ' t make the process exit before we are done .
// trigger the Flex SDK graceful shutdown manually