feat(PingServicesScheduler): implement ping services scheduler endpoints and cache refresh logic for improved service monitoring
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 2m29s

This commit is contained in:
2026-02-22 20:40:57 +07:00
parent 4c7af43be7
commit 431314b973
4 changed files with 249 additions and 50 deletions
+57
View File
@@ -5,6 +5,7 @@
const { sendError, sendOk } = require('../middleware/errorHandler');
const { readS3TextObject, writeS3JsonObject } = require('../services/s3Service');
const networkMapScheduler = require('../services/networkMapScheduler');
const pingServicesScheduler = require('../services/pingServicesScheduler');
const UI_SETTINGS_KEY = 'bgp_data/rt_ui_settings.json';
const NETWORK_MAP_CACHE_KEY = 'network-map-cache/latest.json';
@@ -17,6 +18,11 @@ const SCHEDULER_KEYS = [
'networkMapSchedulerLogMaxLines',
];
const PING_SERVICES_SCHEDULER_KEYS = [
'pingServicesSchedulerEnabled',
'pingServicesSchedulerIntervalMinutes',
];
async function readUiSettings() {
try {
const data = await readS3TextObject(UI_SETTINGS_KEY).catch(() => ({ body: '{}' }));
@@ -124,10 +130,61 @@ async function getNetworkMapCache(req, res) {
}
}
// === Ping services scheduler ===
/** GET /api/scheduler/ping-services/settings */
async function getPingServicesSchedulerSettings(req, res) {
try {
const ui = await readUiSettings();
const settings = pingServicesScheduler.getSettingsFromUiSettings(ui);
const nextRunAt = pingServicesScheduler.getNextRunAt(settings);
return res.json({ ...settings, nextRunAt: nextRunAt || undefined });
} catch (e) {
console.error('[scheduler] getPingServicesSettings', e);
return sendError(res, 500, 'Не удалось прочитать настройки', 'E_SCHEDULER');
}
}
/** PATCH /api/scheduler/ping-services/settings */
async function patchPingServicesSchedulerSettings(req, res) {
try {
const body = req.body || {};
const current = await readUiSettings();
for (const key of PING_SERVICES_SCHEDULER_KEYS) {
if (Object.prototype.hasOwnProperty.call(body, key)) {
current[key] = body[key];
}
}
await writeS3JsonObject(UI_SETTINGS_KEY, current);
const settings = pingServicesScheduler.getSettingsFromUiSettings(current);
return res.json(settings);
} catch (e) {
console.error('[scheduler] patchPingServicesSettings', e);
return sendError(res, 500, 'Не удалось сохранить настройки', 'E_SCHEDULER');
}
}
/** POST /api/scheduler/ping-services/run-now */
async function runPingServicesSchedulerNow(req, res) {
try {
const { refreshPingServicesCache } = require('./miscRoutes');
refreshPingServicesCache().catch((err) => {
console.error('[scheduler] ping-services run-now failed', err);
});
return sendOk(res, { message: 'Обновление кеша пинг-сервисов запущено в фоне' });
} catch (e) {
console.error('[scheduler] ping-services run-now', e);
return sendError(res, 500, 'Не удалось запустить', 'E_SCHEDULER');
}
}
module.exports = {
getNetworkMapSchedulerSettings,
patchNetworkMapSchedulerSettings,
getNetworkMapSchedulerLogs,
runNetworkMapSchedulerNow,
getNetworkMapCache,
getPingServicesSchedulerSettings,
patchPingServicesSchedulerSettings,
runPingServicesSchedulerNow,
};