2022-12-11 13:33:26 +00:00
|
|
|
const { log } = require("../src/util");
|
|
|
|
class UptimeCacheList {
|
|
|
|
/**
|
|
|
|
* list[monitorID][duration]
|
|
|
|
*/
|
|
|
|
static list = {};
|
|
|
|
|
|
|
|
/**
|
2023-01-05 22:19:05 +00:00
|
|
|
* Get the uptime for a specific period
|
2023-08-11 07:46:41 +00:00
|
|
|
* @param {number} monitorID ID of monitor to query
|
|
|
|
* @param {number} duration Duration to query
|
|
|
|
* @returns {(number|null)} Uptime for provided duration, if it exists
|
2022-12-11 13:33:26 +00:00
|
|
|
*/
|
|
|
|
static getUptime(monitorID, duration) {
|
|
|
|
if (UptimeCacheList.list[monitorID] && UptimeCacheList.list[monitorID][duration]) {
|
|
|
|
log.debug("UptimeCacheList", "getUptime: " + monitorID + " " + duration);
|
|
|
|
return UptimeCacheList.list[monitorID][duration];
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-05 22:19:05 +00:00
|
|
|
/**
|
|
|
|
* Add uptime for specified monitor
|
2023-08-11 07:46:41 +00:00
|
|
|
* @param {number} monitorID ID of monitor to insert for
|
|
|
|
* @param {number} duration Duration to insert for
|
2023-01-05 22:19:05 +00:00
|
|
|
* @param {number} uptime Uptime to add
|
2023-08-11 07:46:41 +00:00
|
|
|
* @returns {void}
|
2023-01-05 22:19:05 +00:00
|
|
|
*/
|
2022-12-11 13:33:26 +00:00
|
|
|
static addUptime(monitorID, duration, uptime) {
|
|
|
|
log.debug("UptimeCacheList", "addUptime: " + monitorID + " " + duration);
|
|
|
|
if (!UptimeCacheList.list[monitorID]) {
|
|
|
|
UptimeCacheList.list[monitorID] = {};
|
|
|
|
}
|
|
|
|
UptimeCacheList.list[monitorID][duration] = uptime;
|
|
|
|
}
|
|
|
|
|
2023-01-05 22:19:05 +00:00
|
|
|
/**
|
|
|
|
* Clear cache for specified monitor
|
2023-08-11 07:46:41 +00:00
|
|
|
* @param {number} monitorID ID of monitor to clear
|
|
|
|
* @returns {void}
|
2023-01-05 22:19:05 +00:00
|
|
|
*/
|
2022-12-11 13:33:26 +00:00
|
|
|
static clearCache(monitorID) {
|
|
|
|
log.debug("UptimeCacheList", "clearCache: " + monitorID);
|
|
|
|
delete UptimeCacheList.list[monitorID];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
UptimeCacheList,
|
|
|
|
};
|