Feat/maintenance window check, resolves #467 (#476)

* Added createMaintenanceWindow route

* Added getMaintenanceWindowsByUserId

* Added getMaintenaceWindowsByMonitorId method, updated routes

* Exported delete methods

* Add check for maintenance window before executing job
This commit is contained in:
Alexander Holliday
2024-07-30 10:02:04 -07:00
committed by GitHub
parent 95dfc8d82c
commit bdf8d6aaea

View File

@@ -59,9 +59,34 @@ class JobQueue {
QUEUE_NAME,
async (job) => {
try {
// TODO wrap this in a check to see if a maintenace window is active
// If so, don't process the job
const res = await this.networkService.getStatus(job);
// Get all maintenance windows for this monitor
const monitorId = job.data._id;
const maintenanceWindows =
await this.db.getMaintenanceWindowsByMonitorId(monitorId);
// Check for active maintenance window:
const maintenanceWindowActive = maintenanceWindows.reduce(
(acc, window) => {
if (window.active) {
const start = new Date(window.start);
const end = new Date(window.end);
if (start < new Date() && end > new Date()) {
return true;
}
}
return acc;
},
false
);
if (!maintenanceWindowActive) {
const res = await this.networkService.getStatus(job);
} else {
logger.info(`Monitor ${monitorId} is in maintenance window`, {
service: SERVICE_NAME,
monitorId,
});
}
} catch (error) {
logger.error(`Error processing job ${job.id}: ${error.message}`, {
service: SERVICE_NAME,