mirror of
https://github.com/Unleash/unleash.git
synced 2024-10-18 20:09:08 +02:00
29 lines
859 B
TypeScript
29 lines
859 B
TypeScript
|
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;
|