feat: Add NOTIFICATION_TEST_MODE for cron testing
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user