Skip to content

Commit a208007

Browse files
committed
modify: index 에서 gracefulShutdown 발생시 cache connection 끊기 추가, 그에 따라 모두 비동기 형태로 변경
1 parent 905beff commit a208007

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import app from '@/app';
22
import logger from '@/configs/logger.config';
3+
import { closeCache } from './configs/cache.config';
34

45
const port = parseInt(process.env.PORT || '8080', 10);
56

@@ -13,8 +14,9 @@ const server = app.listen(port, () => {
1314
});
1415

1516
// 기본적인 graceful shutdown 추가
16-
const gracefulShutdown = (signal: string) => {
17+
const gracefulShutdown = async (signal: string) => {
1718
logger.info(`${signal} received, shutting down gracefully`);
19+
await closeCache();
1820

1921
server.close(() => {
2022
logger.info('HTTP server closed');
@@ -28,16 +30,16 @@ const gracefulShutdown = (signal: string) => {
2830
}, 10000);
2931
};
3032

31-
process.on('SIGTERM', () => gracefulShutdown('SIGTERM'));
32-
process.on('SIGINT', () => gracefulShutdown('SIGINT'));
33+
process.on('SIGTERM', async () => gracefulShutdown('SIGTERM'));
34+
process.on('SIGINT', async () => gracefulShutdown('SIGINT'));
3335

3436
// 예상치 못한 에러 처리
35-
process.on('uncaughtException', (error) => {
37+
process.on('uncaughtException', async (error) => {
3638
logger.error('Uncaught Exception:', error);
37-
gracefulShutdown('UNCAUGHT_EXCEPTION');
39+
await gracefulShutdown('UNCAUGHT_EXCEPTION');
3840
});
3941

40-
process.on('unhandledRejection', (reason, promise) => {
42+
process.on('unhandledRejection', async (reason, promise) => {
4143
logger.error('Unhandled Rejection at:', promise, 'reason:', reason);
42-
gracefulShutdown('UNHANDLED_REJECTION');
44+
await gracefulShutdown('UNHANDLED_REJECTION');
4345
});

0 commit comments

Comments
 (0)