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:
@@ -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}).`
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user