From 03904d26e08fbb755983568ed4dec7667f52982a Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Wed, 17 Jul 2024 01:00:00 +0800 Subject: [PATCH] feat: add weekly and monthly cron job --- src/server/cronjob/index.ts | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/server/cronjob/index.ts b/src/server/cronjob/index.ts index 21607e0..37f5e9f 100644 --- a/src/server/cronjob/index.ts +++ b/src/server/cronjob/index.ts @@ -35,11 +35,44 @@ export function initCronjob() { } }); + const weeklyJob = Cron('0 2 * * 1', async () => { + logger.info('Start weekly cronjob'); + + try { + await Promise.all([ + checkFeedEventsNotify(FeedChannelNotifyFrequency.week), + ]); + + logger.info('Weekly cronjob completed'); + } catch (err) { + logger.error('Weekly cronjob error:', err); + } + }); + + const monthlyJob = Cron('0 2 1 * *', async () => { + logger.info('Start monthly cronjob'); + + try { + await Promise.all([ + checkFeedEventsNotify(FeedChannelNotifyFrequency.month), + ]); + + logger.info('Monthly cronjob completed'); + } catch (err) { + logger.error('Monthly cronjob error:', err); + } + }); + // TODO: add more cronjob logger.info('Daily job will start at:', dailyJob.nextRun()?.toISOString()); + logger.info('Weekly job will start at:', weeklyJob.nextRun()?.toISOString()); + logger.info( + 'Monthly job will start at:', + monthlyJob.nextRun()?.toISOString() + ); - return { dailyJob }; + return { dailyJob, weeklyJob, monthlyJob }; } async function statDailyUsage() {