diff --git a/src/app.module.ts b/src/app.module.ts index 13922a2..36947df 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -6,6 +6,7 @@ import {AdminModule} from "./modules/webtoon/admin/admin.module"; import {ThrottlerGuard, ThrottlerModule} from "@nestjs/throttler"; import {APP_GUARD} from "@nestjs/core"; import {MigrationModule} from "./modules/webtoon/migration/migration.module"; +import {ScheduleModule} from "@nestjs/schedule"; @Module({ imports: [ @@ -14,6 +15,7 @@ import {MigrationModule} from "./modules/webtoon/migration/migration.module"; ttl: 60000, limit: 50, }]), + ScheduleModule.forRoot(), TaskModule, WebtoonModule, AdminModule, diff --git a/src/modules/task/task.module.ts b/src/modules/task/task.module.ts index 4920a49..006d95b 100644 --- a/src/modules/task/task.module.ts +++ b/src/modules/task/task.module.ts @@ -1,8 +1,9 @@ import {Module} from "@nestjs/common"; +import {WebtoonUpdateTask} from "./webtoon_update.task"; +import {WebtoonModule} from "../webtoon/webtoon/webtoon.module"; @Module({ - imports: [], - controllers: [], - providers: [], + providers: [WebtoonUpdateTask], + imports: [WebtoonModule] }) export class TaskModule{} diff --git a/src/modules/task/webtoon_update.task.ts b/src/modules/task/webtoon_update.task.ts new file mode 100644 index 0000000..16acbce --- /dev/null +++ b/src/modules/task/webtoon_update.task.ts @@ -0,0 +1,18 @@ +import {Injectable} from "@nestjs/common"; +import {Cron} from "@nestjs/schedule"; +import {DownloadManagerService} from "../webtoon/webtoon/download-manager.service"; + + +@Injectable() +export class WebtoonUpdateTask{ + + constructor( + private readonly downloadManagerService: DownloadManagerService + ){} + + @Cron("0 0 17 * * *") + async handleCron(){ + // Called every day at 17:00 + this.downloadManagerService.updateAllWebtoons(); + } +}