button zum prüfen
This commit is contained in:
@@ -137,10 +137,10 @@ async function sendStoreWatchSummaryNotification({ profileId, entries = [], trig
|
||||
.join('\n');
|
||||
const prefix =
|
||||
triggeredBy === 'manual'
|
||||
? 'Manuell angestoßene Store-Watch-Prüfung abgeschlossen:'
|
||||
? 'Manuell angestoßene Store-Watch-Aktualisierung abgeschlossen:'
|
||||
: 'Store-Watch-Prüfung abgeschlossen:';
|
||||
const title =
|
||||
triggeredBy === 'manual' ? 'Ad-hoc Store-Watch-Prüfung' : 'Store-Watch-Prüfung';
|
||||
triggeredBy === 'manual' ? 'Store-Watch-Aktualisierung' : 'Store-Watch-Prüfung';
|
||||
const message = `${prefix}\n${lines}`;
|
||||
await notifyChannels(profileId, {
|
||||
title,
|
||||
|
||||
@@ -5,6 +5,7 @@ const { DEFAULT_SETTINGS } = require('./adminConfig');
|
||||
const notificationService = require('./notificationService');
|
||||
const { readConfig, writeConfig } = require('./configStore');
|
||||
const { readStoreWatch, writeStoreWatch } = require('./storeWatchStore');
|
||||
const { setStoreStatus, persistStoreStatusCache } = require('./storeStatusCache');
|
||||
|
||||
function wait(ms) {
|
||||
if (!ms || ms <= 0) {
|
||||
@@ -428,6 +429,7 @@ async function checkWatchedStores(sessionId, settings = DEFAULT_SETTINGS, option
|
||||
|
||||
const perRequestDelay = Math.max(0, Number(settings?.storeWatchRequestDelayMs) || 0);
|
||||
let changed = false;
|
||||
let statusCacheUpdated = false;
|
||||
const summary = [];
|
||||
for (let index = 0; index < watchers.length; index += 1) {
|
||||
const watcher = watchers[index];
|
||||
@@ -449,6 +451,8 @@ async function checkWatchedStores(sessionId, settings = DEFAULT_SETTINGS, option
|
||||
}
|
||||
watcher.lastStatusCheckAt = checkedAt;
|
||||
changed = true;
|
||||
setStoreStatus(watcher.storeId, { teamSearchStatus: status, fetchedAt: checkedAt });
|
||||
statusCacheUpdated = true;
|
||||
summary.push({
|
||||
storeId: watcher.storeId,
|
||||
storeName: watcher.storeName,
|
||||
@@ -477,6 +481,9 @@ async function checkWatchedStores(sessionId, settings = DEFAULT_SETTINGS, option
|
||||
if (changed) {
|
||||
writeStoreWatch(session.profile.id, watchers);
|
||||
}
|
||||
if (statusCacheUpdated) {
|
||||
persistStoreStatusCache();
|
||||
}
|
||||
if (options.sendSummary && summary.length > 0) {
|
||||
try {
|
||||
await notificationService.sendStoreWatchSummaryNotification({
|
||||
|
||||
66
services/storeStatusCache.js
Normal file
66
services/storeStatusCache.js
Normal file
@@ -0,0 +1,66 @@
|
||||
const { readStoreStatus, writeStoreStatus } = require('./storeStatusStore');
|
||||
|
||||
const storeStatusCache = new Map();
|
||||
|
||||
function normalizeStatusEntry(entry = {}) {
|
||||
const status = Number(entry.teamSearchStatus);
|
||||
const fetchedAt = Number(entry.fetchedAt) || 0;
|
||||
return {
|
||||
teamSearchStatus: Number.isFinite(status) ? status : null,
|
||||
fetchedAt
|
||||
};
|
||||
}
|
||||
|
||||
(function bootstrapStoreStatusCache() {
|
||||
try {
|
||||
const cached = readStoreStatus();
|
||||
Object.entries(cached || {}).forEach(([storeId, entry]) => {
|
||||
if (!storeId) {
|
||||
return;
|
||||
}
|
||||
storeStatusCache.set(String(storeId), normalizeStatusEntry(entry));
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('[STORE-STATUS] Bootstrap fehlgeschlagen:', error.message);
|
||||
}
|
||||
})();
|
||||
|
||||
function getStoreStatus(storeId) {
|
||||
if (!storeId) {
|
||||
return null;
|
||||
}
|
||||
return storeStatusCache.get(String(storeId)) || null;
|
||||
}
|
||||
|
||||
function setStoreStatus(storeId, data = {}) {
|
||||
if (!storeId) {
|
||||
return null;
|
||||
}
|
||||
const normalized = normalizeStatusEntry(data);
|
||||
storeStatusCache.set(String(storeId), normalized);
|
||||
return normalized;
|
||||
}
|
||||
|
||||
function bulkSetStoreStatus(entries = []) {
|
||||
entries.forEach((entry) => {
|
||||
if (!entry || !entry.storeId) {
|
||||
return;
|
||||
}
|
||||
setStoreStatus(entry.storeId, entry);
|
||||
});
|
||||
}
|
||||
|
||||
function persistStoreStatusCache() {
|
||||
const payload = {};
|
||||
storeStatusCache.forEach((value, key) => {
|
||||
payload[key] = value;
|
||||
});
|
||||
writeStoreStatus(payload);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getStoreStatus,
|
||||
setStoreStatus,
|
||||
bulkSetStoreStatus,
|
||||
persistStoreStatusCache
|
||||
};
|
||||
Reference in New Issue
Block a user