From 8c9912db9deb9dff225c13bd77315b26a9e3236a Mon Sep 17 00:00:00 2001 From: richardtekula Date: Mon, 15 Dec 2025 15:57:19 +0100 Subject: [PATCH] feat: Add NOTIFICATION_TEST_MODE for cron testing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When NOTIFICATION_TEST_MODE=true, cron runs every minute instead of at the scheduled time. Useful for testing email notifications. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- src/cron/calendar/index.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/cron/calendar/index.js b/src/cron/calendar/index.js index 0a466b4..c539a64 100644 --- a/src/cron/calendar/index.js +++ b/src/cron/calendar/index.js @@ -16,16 +16,34 @@ const parseNotificationTime = () => { }; }; +/** + * Check if test mode is enabled + * @returns {boolean} + */ +const isTestMode = () => { + return process.env.NOTIFICATION_TEST_MODE === 'true'; +}; + /** * Start the calendar notification cron job */ export const startCalendarNotificationCron = () => { - const { hour, minute } = parseNotificationTime(); + let cronExpression; + let description; - // Cron expression: minute hour * * * (every day at specified time) - const cronExpression = `${minute} ${hour} * * *`; + if (isTestMode()) { + // Test mode: run every minute + cronExpression = '* * * * *'; + description = 'každú minútu (TEST MODE)'; + logger.warn('NOTIFICATION_TEST_MODE je zapnutý - cron beží každú minútu!'); + } else { + // Production mode: run at specified time + const { hour, minute } = parseNotificationTime(); + cronExpression = `${minute} ${hour} * * *`; + description = `${hour}:${minute.padStart(2, '0')} každý deň`; + } - logger.info(`Nastavujem cron pre kalendárne notifikácie: ${cronExpression} (${hour}:${minute.padStart(2, '0')} každý deň)`); + logger.info(`Nastavujem cron pre kalendárne notifikácie: ${cronExpression} (${description})`); const task = cron.schedule(cronExpression, async () => { logger.info('Cron job spustený - kontrolujem zajtrajšie udalosti'); @@ -41,7 +59,7 @@ export const startCalendarNotificationCron = () => { timezone: 'Europe/Bratislava', }); - logger.success(`Kalendárny notifikačný cron naplánovaný na ${hour}:${minute.padStart(2, '0')} (Europe/Bratislava)`); + logger.success(`Kalendárny notifikačný cron naplánovaný: ${description} (Europe/Bratislava)`); return task; };