-
Notifications
You must be signed in to change notification settings - Fork 5
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
[BE] fix-room-clean #298
[BE] fix-room-clean #298
Conversation
Copilot
AI
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 suggestion.
Comments skipped due to low confidence (1)
BE/src/game/redis/game-redis-memory.service.ts:25
- There is a redundant comment for the checkInactiveRooms method. The comment on line 25 can be removed.
/**
@@ -37,6 +37,15 @@ export class RoomCleanupSubscriber extends RedisSubscriber { | |||
try { | |||
const pipeline = this.redis.pipeline(); | |||
|
|||
// 1. ๋ฐฉ์ ์ํ ํ๋ ์ด์ด ๋ชฉ๋ก ๊ฐ์ ธ์ค๊ธฐ, 200๋ช ๋ฏธ๋ง -> smembers ์ฌ์ฉ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment has a minor spelling issue. It should be '200๋ช ๋ฏธ๋ง -> smembers ์ฌ์ฉ!' instead of '200๋ช ๋ฏธ๋ง -> smembers ์ฌ์ฉ!'.
// 1. ๋ฐฉ์ ์ํ ํ๋ ์ด์ด ๋ชฉ๋ก ๊ฐ์ ธ์ค๊ธฐ, 200๋ช ๋ฏธ๋ง -> smembers ์ฌ์ฉ! | |
// 1. ๋ฐฉ์ ์ํ ํ๋ ์ด์ด ๋ชฉ๋ก ๊ฐ์ ธ์ค๊ธฐ, 200๋ช ๋ฏธ๋ง -> smembers ์ฌ์ฉ! |
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๐๐
@Cron(CronExpression.EVERY_10_MINUTES) | ||
async checkInactiveRooms(): Promise<void> { | ||
this.logger.verbose('๋นํ์ฑ ๋ฐฉ ์ฒดํฌ ์์'); | ||
try { | ||
const now = Date.now(); | ||
let cursor = '0'; | ||
let processedCount = 0; | ||
|
||
do { | ||
// SCAN์ ์ฌ์ฉํ์ฌ ๋ฐฐ์น ๋จ์๋ก ์ฒ๋ฆฌ | ||
const [nextCursor, rooms] = await this.redis.sscan( | ||
REDIS_KEY.ACTIVE_ROOMS, | ||
cursor, | ||
'COUNT', | ||
this.BATCH_SIZE | ||
); | ||
cursor = nextCursor; | ||
|
||
// ๋ณ๋ ฌ๋ก ๋ฐฉ ์ํ ์ฒดํฌ ๋ฐ ์ฒ๋ฆฌ | ||
await Promise.all( | ||
rooms.map(async (roomId) => { | ||
try { | ||
const lastActivity = await this.redis.hget(REDIS_KEY.ROOM(roomId), 'lastActivityAt'); | ||
|
||
if (lastActivity && now - parseInt(lastActivity) > this.INACTIVE_THRESHOLD) { | ||
await this.redis.publish('room:cleanup', roomId); | ||
this.logger.verbose(`๋นํ์ฑ์ผ๋ก ์ธํด ๋ฐฉ ${roomId} ์ ๋ฆฌ ์์`); | ||
processedCount++; | ||
} | ||
} catch (error) { | ||
this.logger.error(`๋ฐฉ ${roomId} ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: ${error.message}`); | ||
} | ||
}) | ||
); | ||
} while (cursor !== '0'); | ||
|
||
this.logger.verbose(`๋นํ์ฑ ๋ฐฉ ์ฒดํฌ ์๋ฃ: ${processedCount}๊ฐ ๋ฐฉ ์ ๋ฆฌ๋จ`); | ||
} catch (error) { | ||
this.logger.error(`๋นํ์ฑ ๋ฐฉ ์ฒดํฌ ์ค ์ค๋ฅ ๋ฐ์: ${error.message}`); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: try/catch ๋ฐ๊นฅ์ ํ๋๋ง ๋ฌ๋ ๋ ๊ฒ ๊ฐ์ต๋๋ค!
(์ทจ์)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ๊ทธ๋ฐ๋ฐ ๋ฐ๊นฅ์ ํ๋๋ง ๋๋ฉด rooms.map ๋๋ค๊ฐ ์๋ฌ ๋ฌ์ ๋ ๋ค์ ์ปค์๋ก ๋ชป ๊ฐ๊ฒ ๋ค์.
๊ทธ๋ฌ๋ฉด ๊ทธ ๋์ ์ ์๋ ๋ถ๋ถ์ ํจ์๋ก ๋ถ๋ฆฌํ๋ ๊ฑด ์ด๋จ๊น์? depth๊ฐ ๋๋ฌด ๊น์ด๋ณด์ฌ์์!
async (roomId) => {
try {
const lastActivity = await this.redis.hget(REDIS_KEY.ROOM(roomId), 'lastActivityAt');
if (lastActivity && now - parseInt(lastActivity) > this.INACTIVE_THRESHOLD) {
await this.redis.publish('room:cleanup', roomId);
this.logger.verbose(`๋นํ์ฑ์ผ๋ก ์ธํด ๋ฐฉ ${roomId} ์ ๋ฆฌ ์์`);
processedCount++;
}
} catch (error) {
this.logger.error(`๋ฐฉ ${roomId} ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: ${error.message}`);
}
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๐
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
๐ ์์ ๋ด์ฉ
์ด Pull Request๋ Redis ๊ธฐ๋ฐ ๊ฒ์ ์๋น์ค์์ ๋นํ์ฑ ๋ฐฉ ์ฒ๋ฆฌ์ ์ ๋ฆฌ ํ๋ก์ธ์ค๋ฅผ ๊ฐ์ ํ๊ธฐ ์ํ ์ฌ๋ฌ ์ ๋ฐ์ดํธ๋ฅผ ํฌํจํฉ๋๋ค. ๊ฐ์ฅ ์ค์ํ ๋ณ๊ฒฝ์ฌํญ์ ๋นํ์ฑ ๋ฐฉ ํ์ธ์ ์ํ ์๋ก์ด ๋ฉ์๋ ์ถ๊ฐ, ๋ฐฉ ์ ๋ฆฌ ํ๋ก์ธ์ค ์์ , ๊ทธ๋ฆฌ๊ณ ์ค๋ณต ์ฝ๋ ์ ๊ฑฐ์ ๋๋ค.
๋นํ์ฑ ๋ฐฉ ์ฒ๋ฆฌ ๊ฐ์ :
BE/src/game/redis/game-redis-memory.service.ts: cron ์์ ์ ์ฌ์ฉํ์ฌ ์ฃผ๊ธฐ์ ์ผ๋ก ๋นํ์ฑ ๋ฐฉ์ ํ์ธํ๊ณ ์ ๋ฆฌํ๋ ์๋ก์ด ๋ฉ์๋ checkInactiveRooms๋ฅผ ์ถ๊ฐํ์ต๋๋ค. ์ด ๋ฉ์๋๋ Redis SCAN์ ์ฌ์ฉํ์ฌ ๋๊ท๋ชจ ๋ฐฉ ์ธํธ๋ฅผ ์์ ํ๊ฒ ์ฒ๋ฆฌํ๊ณ ๋ฐฐ์น ๋จ์๋ก ์ฒ๋ฆฌํฉ๋๋ค.
๋ฐฉ ์ ๋ฆฌ ํ๋ก์ธ์ค ๊ฐํ:
BE/src/game/redis/subscribers/room.cleanup.subscriber.ts: ๋ฐฉ ์ ๋ฆฌ ํ๋ก์ธ์ค๋ฅผ ์ ๋ฐ์ดํธํ์ฌ ๋ฐฉ ๋ฐ์ดํฐ ์์ฒด๋ฟ๋ง ์๋๋ผ ํด๋น ๋ฐฉ์ ํ๋ ์ด์ด ๋ชฉ๋ก์ ๊ฐ์ ธ์์ ๊ทธ๋ค์ ๋ฐ์ดํฐ๋ ์ญ์ ํ๋๋ก ์์ ํ์ต๋๋ค.
์ฝ๋ ์ ๋ฆฌ ๋ฐ ๋ฆฌํฉํ ๋ง:
BE/src/game/service/game.room.service.ts: GameRedisMemoryService์ ์๋ก์ด ๊ตฌํ์ผ๋ก ๋์ฒด๋์๊ธฐ ๋๋ฌธ์ ๊ธฐ์กด์ checkInactiveRooms ๋ฉ์๋์ ๊ด๋ จ cron ์์ ์ ์ ๊ฑฐํ์ต๋๋ค.
์ฌ์ํ ๋ณ๊ฒฝ์ฌํญ:
BE/src/game/redis/game-redis-memory.service.ts: ์ผ๊ด๋ ๊ตฌ์กฐ๋ฅผ ๋ฐ๋ฅด๋๋ก imports ์์๋ฅผ ์ฌ์ ๋ ฌํ์ต๋๋ค.
BE/src/game/service/game.room.service.ts: ์ฌ์ฉํ์ง ์๋ import ๊ตฌ๋ฌธ์ ์ ๊ฑฐํ์ต๋๋ค.
๐ผ ์ฐธ๊ณ ์ด๋ฏธ์ง
๐ฏ ๋ฆฌ๋ทฐ ์๊ตฌ์ฌํญ (์ ํ)
โ Check List