-
Notifications
You must be signed in to change notification settings - Fork 0
HOT FIX! 리더보드 캐싱으로 시작된 핫픽스 + 이 참에 업데이트하는 관련 config 값들 #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2fc61a5
modify: db config update, pool 좀 더 세밀하게 관리
Nuung caf66d6
hotfix: run script api image 잘 사용하게 업데이트
Nuung 86d56f0
modify: db config linting
Nuung cabe3fa
modify: app 실행과 index 업데이트, 그에 따른 dbms connection 관련 설정 업데이트
Nuung 919660f
modify: linting
Nuung 0a83c21
modify: index 파일 모듈화, 고도화, 리펙토링
Nuung 7959cb3
modify: index 파일 모듈화, 고도화, 리펙토링, 린팅
Nuung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,45 +1,89 @@ | ||
| import app from '@/app'; | ||
| import logger from '@/configs/logger.config'; | ||
| import { closeCache } from './configs/cache.config'; | ||
| import { closeDatabase, initializeDatabase } from './configs/db.config'; | ||
| import { Server } from 'http'; | ||
|
|
||
| const port = parseInt(process.env.PORT || '8080', 10); | ||
|
|
||
| const server = app.listen(port, () => { | ||
| logger.info(`Server running on port ${port}`); | ||
| logger.info(`Environment: ${process.env.NODE_ENV}`); | ||
| if (process.env.NODE_ENV !== 'production') { | ||
| logger.info(`API Docs: http://localhost:${port}/api-docs`); | ||
| async function startServer() { | ||
| try { | ||
| // 데이터베이스 초기화 | ||
| await initializeDatabase(); | ||
| logger.info('데이터베이스 초기화 완료'); | ||
|
|
||
| // 서버 시작 | ||
| const server = app.listen(port, () => { | ||
| logger.info(`Server running on port ${port}`); | ||
| logger.info(`Environment: ${process.env.NODE_ENV}`); | ||
| if (process.env.NODE_ENV !== 'production') { | ||
| logger.info(`API Docs: http://localhost:${port}/api-docs`); | ||
| } | ||
| logger.info(`Health Check: http://localhost:${port}/health`); | ||
| }); | ||
|
|
||
| // Graceful shutdown 핸들러 설정 | ||
| setupGracefulShutdown(server); | ||
| } catch (error) { | ||
| logger.error('서버 시작 중 오류 발생:', error); | ||
| process.exit(1); | ||
| } | ||
| logger.info(`Health Check: http://localhost:${port}/health`); | ||
| }); | ||
| } | ||
|
|
||
| function setupGracefulShutdown(server: Server) { | ||
| // 기본적인 graceful shutdown 추가 | ||
| const gracefulShutdown = async (signal: string) => { | ||
| logger.info(`${signal} received, shutting down gracefully`); | ||
|
|
||
| try { | ||
| // HTTP 서버 종료 | ||
| await new Promise<void>((resolve) => { | ||
| server.close(() => { | ||
| logger.info('HTTP server closed'); | ||
| resolve(); | ||
| }); | ||
| }); | ||
|
|
||
| // 데이터베이스 연결 종료 | ||
| await closeDatabase(); | ||
|
|
||
| // 기본적인 graceful shutdown 추가 | ||
| const gracefulShutdown = async (signal: string) => { | ||
| logger.info(`${signal} received, shutting down gracefully`); | ||
| await closeCache(); | ||
| // 캐시 연결 종료 | ||
| await closeCache(); | ||
|
|
||
| server.close(() => { | ||
| logger.info('HTTP server closed'); | ||
| process.exit(0); | ||
| logger.info('Graceful shutdown completed'); | ||
| process.exit(0); | ||
| } catch (error) { | ||
| logger.error('Graceful shutdown 중 오류 발생:', error); | ||
| process.exit(1); | ||
| } | ||
| }; | ||
|
|
||
| // 시그널 핸들러 등록 | ||
| process.on('SIGTERM', async () => gracefulShutdown('SIGTERM')); | ||
| process.on('SIGINT', async () => gracefulShutdown('SIGINT')); | ||
|
|
||
| // 예상치 못한 에러 처리 | ||
| process.on('uncaughtException', async (error) => { | ||
| logger.error('Uncaught Exception:', error); | ||
| await gracefulShutdown('UNCAUGHT_EXCEPTION'); | ||
| }); | ||
|
|
||
| process.on('unhandledRejection', async (reason, promise) => { | ||
| logger.error('Unhandled Rejection at:', promise, 'reason:', reason); | ||
| await gracefulShutdown('UNHANDLED_REJECTION'); | ||
| }); | ||
|
|
||
| // 강제 종료 타이머 (10초) | ||
| setTimeout(() => { | ||
| const forceExitTimer = setTimeout(() => { | ||
| logger.error('Could not close connections in time, forcefully shutting down'); | ||
| process.exit(1); | ||
| }, 10000); | ||
| }; | ||
|
|
||
| process.on('SIGTERM', async () => gracefulShutdown('SIGTERM')); | ||
| process.on('SIGINT', async () => gracefulShutdown('SIGINT')); | ||
|
|
||
| // 예상치 못한 에러 처리 | ||
| process.on('uncaughtException', async (error) => { | ||
| logger.error('Uncaught Exception:', error); | ||
| await gracefulShutdown('UNCAUGHT_EXCEPTION'); | ||
| }); | ||
| // graceful shutdown이 완료되면 타이머 해제 | ||
| process.on('exit', () => { | ||
| clearTimeout(forceExitTimer); | ||
| }); | ||
| } | ||
Nuung marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| process.on('unhandledRejection', async (reason, promise) => { | ||
| logger.error('Unhandled Rejection at:', promise, 'reason:', reason); | ||
| await gracefulShutdown('UNHANDLED_REJECTION'); | ||
| }); | ||
| // 서버 시작 | ||
| startServer(); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.