From 27183220a4046cf328cff58384ef54fa2dae3afe Mon Sep 17 00:00:00 2001 From: Nevo David Date: Sat, 9 Mar 2024 20:30:09 +0700 Subject: [PATCH] feat: sync trending --- apps/cron/src/cron.module.ts | 3 ++- apps/cron/src/tasks/sync.trending.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 apps/cron/src/tasks/sync.trending.ts diff --git a/apps/cron/src/cron.module.ts b/apps/cron/src/cron.module.ts index 81bacd00..589d6dcf 100644 --- a/apps/cron/src/cron.module.ts +++ b/apps/cron/src/cron.module.ts @@ -6,6 +6,7 @@ import { DatabaseModule } from '@gitroom/nestjs-libraries/database/prisma/databa import { RedisModule } from '@gitroom/nestjs-libraries/redis/redis.module'; import { BullMqModule } from '@gitroom/nestjs-libraries/bull-mq-transport/bull-mq.module'; import { ioRedis } from '@gitroom/nestjs-libraries/redis/redis.service'; +import { SyncTrending } from '@gitroom/cron/tasks/sync.trending'; @Module({ imports: [ @@ -17,6 +18,6 @@ import { ioRedis } from '@gitroom/nestjs-libraries/redis/redis.service'; }), ], controllers: [], - providers: [RefreshTokens, CheckStars], + providers: [RefreshTokens, CheckStars, SyncTrending], }) export class CronModule {} diff --git a/apps/cron/src/tasks/sync.trending.ts b/apps/cron/src/tasks/sync.trending.ts new file mode 100644 index 00000000..dc5a1a57 --- /dev/null +++ b/apps/cron/src/tasks/sync.trending.ts @@ -0,0 +1,14 @@ +import { Injectable } from '@nestjs/common'; +import { Cron } from '@nestjs/schedule'; +import { BullMqClient } from '@gitroom/nestjs-libraries/bull-mq-transport/client/bull-mq.client'; + +@Injectable() +export class SyncTrending { + constructor( + private _workerServiceProducer: BullMqClient + ) {} + @Cron('0 * * * *') + async syncTrending() { + this._workerServiceProducer.emit('sync_trending', {}).subscribe(); + } +}