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; };