feat: KoePi Filial-Whitelist wird automatisch woechentlich neu aufgeloest
This commit is contained in:
@@ -725,8 +725,25 @@ async function refreshOffersOnly() {
|
||||
// Wird täglich um 06:00 vom Scheduler in index.js aufgerufen (ohne onlyUserId
|
||||
// → geht an alle). forceNotify=true (manueller Admin-Test): Pushover wird auch
|
||||
// ohne Änderung verschickt; onlyUserId gesetzt: nur an diesen einen Nutzer.
|
||||
// Löst die Filial-Whitelist automatisch neu auf, wenn die letzte Auflösung
|
||||
// mehr als 6 Tage her ist — läuft als Teil des täglichen 06:00-Checks, damit
|
||||
// ein einmalig falscher/veralteter Treffer sich von selbst korrigiert, statt
|
||||
// dauerhaft stehen zu bleiben.
|
||||
const RESOLVE_MAX_AGE_DAYS = 6;
|
||||
async function resolveLocalStoresIfStale() {
|
||||
const row = db.prepare('SELECT MIN(resolved_at) AS oldest FROM koepi_local_stores').get();
|
||||
const oldest = row?.oldest;
|
||||
const staleOrMissing = !oldest ||
|
||||
(Date.now() - new Date(oldest.replace(' ', 'T')).getTime()) > RESOLVE_MAX_AGE_DAYS * 24 * 60 * 60 * 1000;
|
||||
if (!staleOrMissing) return;
|
||||
console.log(`🍺 KöPi: Filial-Whitelist ist älter als ${RESOLVE_MAX_AGE_DAYS} Tage (oder unvollständig) — löse automatisch neu auf...`);
|
||||
try { await resolveLocalStores(); }
|
||||
catch (e) { console.error('🍺 KöPi: automatische Neu-Auflösung fehlgeschlagen:', e.message); }
|
||||
}
|
||||
|
||||
async function runDailyCheck(forceNotify = false, onlyUserId = null) {
|
||||
try {
|
||||
await resolveLocalStoresIfStale();
|
||||
const { offers } = await scrapeMarktguru(true);
|
||||
const currentSig = offerSignature(offers);
|
||||
const lastSig = db.prepare('SELECT value FROM admin_settings WHERE key=?').get(KOEPI_SETTINGS_KEY)?.value || '';
|
||||
|
||||
Reference in New Issue
Block a user