* 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:
1 parent
95dfc8d82c
commit
bdf8d6aaea
1 file changed
+28
-3
@@ -59,9 +59,34 @@ class JobQueue {
|
|||||||
QUEUE_NAME,
|
QUEUE_NAME,
|
||||||
async (job) => {
|
async (job) => {
|
||||||
try {
|
try {
|
||||||
// TODO wrap this in a check to see if a maintenace window is active
|
// Get all maintenance windows for this monitor
|
||||||
// If so, don't process the job
|
const monitorId = job.data._id;
|
||||||
const res = await this.networkService.getStatus(job);
|
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) {
|
} catch (error) {
|
||||||
logger.error(`Error processing job ${job.id}: ${error.message}`, {
|
logger.error(`Error processing job ${job.id}: ${error.message}`, {
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
|
|||||||
Reference in new issue
Block a user