update
This commit is contained in:
@@ -17,10 +17,13 @@ import nextcloudService from '../services/nextcloud.service';
|
||||
import logger from '../utils/logger';
|
||||
|
||||
const INTERVAL_MS = 15 * 60 * 1000; // 15 minutes
|
||||
const NEXTCLOUD_INTERVAL_MS = 2 * 60 * 1000; // 2 minutes
|
||||
const ATEMSCHUTZ_THRESHOLD = 60; // days
|
||||
|
||||
let jobInterval: ReturnType<typeof setInterval> | null = null;
|
||||
let nextcloudInterval: ReturnType<typeof setInterval> | null = null;
|
||||
let isRunning = false;
|
||||
let isNextcloudRunning = false;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Core generation function
|
||||
@@ -36,7 +39,6 @@ export async function runNotificationGeneration(): Promise<void> {
|
||||
await generateAtemschutzNotifications();
|
||||
await generateVehicleNotifications();
|
||||
await generateEquipmentNotifications();
|
||||
await generateNextcloudTalkNotifications();
|
||||
await notificationService.deleteOldRead();
|
||||
} catch (error) {
|
||||
logger.error('NotificationGenerationJob: unexpected error', {
|
||||
@@ -47,6 +49,23 @@ export async function runNotificationGeneration(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
async function runNextcloudNotificationGeneration(): Promise<void> {
|
||||
if (isNextcloudRunning) {
|
||||
logger.warn('NotificationGenerationJob: Nextcloud run still in progress — skipping');
|
||||
return;
|
||||
}
|
||||
isNextcloudRunning = true;
|
||||
try {
|
||||
await generateNextcloudTalkNotifications();
|
||||
} catch (error) {
|
||||
logger.error('NotificationGenerationJob: Nextcloud unexpected error', {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
});
|
||||
} finally {
|
||||
isNextcloudRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 1. Atemschutz personal warnings
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -299,20 +318,29 @@ export function startNotificationJob(): void {
|
||||
return;
|
||||
}
|
||||
|
||||
// Run once on startup, then repeat.
|
||||
// Run both once on startup, then repeat on separate intervals.
|
||||
runNotificationGeneration();
|
||||
runNextcloudNotificationGeneration();
|
||||
|
||||
jobInterval = setInterval(() => {
|
||||
runNotificationGeneration();
|
||||
}, INTERVAL_MS);
|
||||
|
||||
logger.info('Notification generation job scheduled (setInterval, 15min interval)');
|
||||
nextcloudInterval = setInterval(() => {
|
||||
runNextcloudNotificationGeneration();
|
||||
}, NEXTCLOUD_INTERVAL_MS);
|
||||
|
||||
logger.info('Notification generation jobs scheduled (main: 15min, Nextcloud Talk: 2min)');
|
||||
}
|
||||
|
||||
export function stopNotificationJob(): void {
|
||||
if (jobInterval !== null) {
|
||||
clearInterval(jobInterval);
|
||||
jobInterval = null;
|
||||
logger.info('Notification generation job stopped');
|
||||
}
|
||||
if (nextcloudInterval !== null) {
|
||||
clearInterval(nextcloudInterval);
|
||||
nextcloudInterval = null;
|
||||
}
|
||||
logger.info('Notification generation jobs stopped');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user