1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/src/lib/util/graceful-shutdown.ts

29 lines
859 B
TypeScript
Raw Normal View History

import { Logger } from '../logger';
import { IUnleash } from '../types/core';
function registerGracefulShutdown(unleash: IUnleash, logger: Logger): void {
process.on('SIGINT', async () => {
try {
logger.info('Graceful shutdown signal (SIGINT) received.');
await unleash.stop();
process.exit(0);
} catch (e) {
logger.error('Unable to shutdown Unleash. Hard exit!', e);
process.exit(1);
}
});
process.on('SIGTERM', async () => {
try {
logger.info('Graceful shutdown signal (SIGTERM) received.');
await unleash.stop();
process.exit(0);
} catch (e) {
logger.error('Unable to shutdown Unleash. Hard exit!', e);
process.exit(1);
}
});
}
export default registerGracefulShutdown;