Skip to content

Commit 0b22d04

Browse files
committed
feat: nest 스케줄러 DI 컨테이너에 등록
1 parent 92680b0 commit 0b22d04

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Module } from '@nestjs/common';
2+
import { TasksService } from './tasks.service';
3+
import { RedisModule } from '../redis/redis.module';
4+
import { PageModule } from '../page/page.module';
5+
6+
@Module({
7+
imports: [RedisModule, PageModule],
8+
providers: [TasksService],
9+
})
10+
export class TasksModule {}

apps/backend/src/tasks/tasks.service.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Injectable, Logger } from '@nestjs/common';
22
import { Cron, CronExpression } from '@nestjs/schedule';
33
import { RedisService } from '../redis/redis.service';
44
import { PageService } from '../page/page.service';
5+
import { PageNotFoundException } from 'src/exception/page.exception';
56

67
@Injectable()
78
export class TasksService {
@@ -11,7 +12,7 @@ export class TasksService {
1112
private readonly pageService: PageService,
1213
) {}
1314

14-
@Cron(CronExpression.EVERY_MINUTE)
15+
@Cron(CronExpression.EVERY_SECOND)
1516
async handleCron() {
1617
console.log(await this.redisService.getAllKeys());
1718
const keys = await this.redisService.getAllKeys();
@@ -32,6 +33,11 @@ export class TasksService {
3233
});
3334
this.logger.log('데이터베이스 갱신');
3435
}
35-
this.pageService.updateBulkPage(pages);
36+
try {
37+
this.pageService.updateBulkPage(pages);
38+
} catch (exception) {
39+
if (exception instanceof PageNotFoundException) {
40+
}
41+
}
3642
}
3743
}

0 commit comments

Comments
 (0)