fix: keep background jobs alive

Add a background job orchestrator that restores profile jobs from saved credentials,
keeps pickup and store-watch schedules alive without UI logins, and exposes job
status via health/admin endpoints.
This commit is contained in:
2026-06-25 12:40:28 +02:00
parent 881b3d8d86
commit 02dfea8562
5 changed files with 308 additions and 6 deletions

View File

@@ -1122,7 +1122,7 @@ function scheduleStoreWatchers(sessionId, settings) {
return false;
}
const cronExpression = effectiveSettings.storeWatchCron || DEFAULT_SETTINGS.storeWatchCron;
const job = cron.schedule(
const cronJob = cron.schedule(
cronExpression,
() => {
checkWatchedStores(sessionId, effectiveSettings).catch((error) => {
@@ -1131,14 +1131,22 @@ function scheduleStoreWatchers(sessionId, settings) {
},
{ timezone: 'Europe/Berlin' }
);
sessionStore.attachJob(sessionId, job);
setTimeout(
let initialTimeout = setTimeout(
() => checkWatchedStores(sessionId, effectiveSettings),
randomDelayMs(
effectiveSettings.storeWatchInitialDelayMinSeconds,
effectiveSettings.storeWatchInitialDelayMaxSeconds
)
);
sessionStore.attachJob(sessionId, {
stop: () => {
cronJob.stop();
if (initialTimeout) {
clearTimeout(initialTimeout);
initialTimeout = null;
}
}
});
console.log(
`[WATCH] Überwache ${watchers.length} Betriebe für Session ${sessionId} (Cron: ${cronExpression}).`
);