All files / src/lib/util graceful-shutdown.ts

50% Statements 7/14
100% Branches 0/0
66.67% Functions 2/3
46.15% Lines 6/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25        15x                       5x   5x 5x 5x     2x  
import { Logger } from '../logger';
import { IUnleash } from '../types/core';
 
function registerGracefulShutdown(unleash: IUnleash, logger: Logger): void {
    const unleashCloser = (signal: string) => async () => {
        try {
            logger.info(`Graceful shutdown signal (${signal}) received.`);
            await unleash.stop();
            logger.info('Unleash has been successfully stopped.');
            process.exit(0);
        } catch (e) {
            logger.error('Unable to shutdown Unleash. Hard exit!');
            process.exit(1);
        }
    };
 
    logger.debug('Registering graceful shutdown');
 
    process.on('SIGINT', unleashCloser('SIGINT'));
    process.on('SIGHUP', unleashCloser('SIGHUP'));
    process.on('SIGTERM', unleashCloser('SIGTERM'));
}
 
export default registerGracefulShutdown;