Skip to content

Commit a5f1cbd

Browse files
committed
fix: cron module import & 메서드 호출 x 변경
1 parent 14300f2 commit a5f1cbd

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

DBManager/src/active-user/active-user.service.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ export class ActiveUserService implements OnModuleInit {
1010
onModuleInit() {
1111
this.countUp();
1212
this.countDown();
13-
this.applyToRedis();
1413
}
1514

1615
private countUp() {
1716
const channel = '__keyspace@1__:APPEND';
18-
this.redisService.subscribeActiveUser(channel, async (sid) => {
19-
const pod = await this.redisService.hgetSession(sid, 'pod');
17+
this.redisService.subscribeActiveUser(channel, async (sessionId) => {
18+
const pod = await this.redisService.hgetSession(sessionId, 'pod');
2019

2120
const currentCount = this.activeUserVariation.get(pod) ?? 0;
2221
this.activeUserVariation.set(pod, currentCount + 1);
@@ -25,16 +24,16 @@ export class ActiveUserService implements OnModuleInit {
2524

2625
private countDown() {
2726
const channel = '__keyspace@1__:EXPIRE';
28-
this.redisService.subscribeActiveUser(channel, async (sid) => {
29-
const pod = await this.redisService.hgetSession(sid, 'pod');
27+
this.redisService.subscribeActiveUser(channel, async (sessionId) => {
28+
const pod = await this.redisService.hgetSession(sessionId, 'pod');
3029

3130
const currentCount = this.activeUserVariation.get(pod) ?? 0;
3231
this.activeUserVariation.set(pod, currentCount - 1);
3332
});
3433
}
3534

3635
@Cron(CronExpression.EVERY_MINUTE)
37-
private async applyToRedis() {
36+
async applyToRedis() {
3837
for (const [pod, variation] of this.activeUserVariation.entries()) {
3938
const count = await this.redisService.hgetPod(pod, 'activeUser');
4039
const newCount = (count ? parseInt(count, 10) : 0) + variation;

DBManager/src/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import { Module } from '@nestjs/common';
22
import { AppController } from './app.controller';
33
import { KubernetesService } from './K8S/KubernetesService';
44
import { ConfigModule } from '@nestjs/config';
5+
import { ScheduleModule } from '@nestjs/schedule';
56

67
@Module({
78
imports: [
89
ConfigModule.forRoot({
910
isGlobal: true,
1011
}),
12+
ScheduleModule.forRoot(),
1113
],
1214
controllers: [AppController],
1315
providers: [KubernetesService],

0 commit comments

Comments
 (0)