This commit is contained in:
Matthias Hochmeister
2026-03-13 15:04:40 +01:00
parent 8d9388ca9a
commit 7833dca29c
3 changed files with 25 additions and 7 deletions

View File

@@ -17,7 +17,9 @@ 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 NEXTCLOUD_INTERVAL_MS = 5 * 60 * 1000; // 5 minutes — keep reasonable to avoid rate-limiting
const NEXTCLOUD_BATCH_DELAY_MS = 300; // ms between user batches to avoid hammering Nextcloud
const STARTUP_DELAY_MS = 30 * 1000; // 30 seconds — avoid burst on container restart
const ATEMSCHUTZ_THRESHOLD = 60; // days
let jobInterval: ReturnType<typeof setInterval> | null = null;
@@ -267,6 +269,9 @@ async function generateNextcloudTalkNotifications(): Promise<void> {
const users = usersResult.rows;
for (let i = 0; i < users.length; i += NEXTCLOUD_BATCH_SIZE) {
if (i > 0) {
await new Promise((r) => setTimeout(r, NEXTCLOUD_BATCH_DELAY_MS));
}
const batch = users.slice(i, i + NEXTCLOUD_BATCH_SIZE);
await Promise.allSettled(batch.map((user) => processNextcloudUser(user)));
}
@@ -318,9 +323,11 @@ export function startNotificationJob(): void {
return;
}
// Run both once on startup, then repeat on separate intervals.
// Run main job once on startup, then repeat.
runNotificationGeneration();
runNextcloudNotificationGeneration();
// Delay initial Nextcloud run to avoid a burst on container restart.
setTimeout(() => runNextcloudNotificationGeneration(), STARTUP_DELAY_MS);
jobInterval = setInterval(() => {
runNotificationGeneration();