mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-05-24 03:49:35 -05:00
remove incidents on delete
This commit is contained in:
@@ -245,6 +245,7 @@ export const initializeServices = async ({
|
||||
checksRepository,
|
||||
monitorStatsRepository,
|
||||
statusPagesRepository,
|
||||
incidentsRepository,
|
||||
});
|
||||
|
||||
const statusPageService = new StatusPageService(statusPagesRepository);
|
||||
|
||||
@@ -23,5 +23,6 @@ export interface IIncidentsRepository {
|
||||
// update
|
||||
updateById(incidentId: string, teamId: string, updateData: Partial<Incident>): Promise<Incident>;
|
||||
// delete
|
||||
deleteByMonitorId(monitorId: string, teamId: string): Promise<number>;
|
||||
// other
|
||||
}
|
||||
|
||||
@@ -273,5 +273,13 @@ class MongoIncidentRepository implements IIncidentsRepository {
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
||||
deleteByMonitorId = async (monitorId: string, teamId: string) => {
|
||||
const result = await IncidentModel.deleteMany({
|
||||
monitorId: new mongoose.Types.ObjectId(monitorId),
|
||||
teamId: new mongoose.Types.ObjectId(teamId),
|
||||
});
|
||||
return result.deletedCount || 0;
|
||||
};
|
||||
}
|
||||
export default MongoIncidentRepository;
|
||||
|
||||
@@ -8,7 +8,13 @@ import type {
|
||||
PageSpeedDetailsResult,
|
||||
GamesMap,
|
||||
} from "@/types/monitor.js";
|
||||
import type { IChecksRepository, IMonitorsRepository, IMonitorStatsRepository, IStatusPagesRepository } from "@/repositories/index.js";
|
||||
import type {
|
||||
IChecksRepository,
|
||||
IIncidentsRepository,
|
||||
IMonitorsRepository,
|
||||
IMonitorStatsRepository,
|
||||
IStatusPagesRepository,
|
||||
} from "@/repositories/index.js";
|
||||
import fs from "fs";
|
||||
import { fileURLToPath } from "url";
|
||||
import path from "path";
|
||||
@@ -79,6 +85,7 @@ export class MonitorService implements IMonitorService {
|
||||
private checksRepository: IChecksRepository;
|
||||
private monitorStatsRepository: IMonitorStatsRepository;
|
||||
private statusPagesRepository: IStatusPagesRepository;
|
||||
private incidentsRepository: IIncidentsRepository;
|
||||
|
||||
constructor({
|
||||
jobQueue,
|
||||
@@ -89,6 +96,7 @@ export class MonitorService implements IMonitorService {
|
||||
checksRepository,
|
||||
monitorStatsRepository,
|
||||
statusPagesRepository,
|
||||
incidentsRepository,
|
||||
}: {
|
||||
jobQueue: ISuperSimpleQueue;
|
||||
emailService: any;
|
||||
@@ -98,6 +106,7 @@ export class MonitorService implements IMonitorService {
|
||||
checksRepository: IChecksRepository;
|
||||
monitorStatsRepository: IMonitorStatsRepository;
|
||||
statusPagesRepository: IStatusPagesRepository;
|
||||
incidentsRepository: IIncidentsRepository;
|
||||
}) {
|
||||
this.jobQueue = jobQueue;
|
||||
this.emailService = emailService;
|
||||
@@ -107,6 +116,7 @@ export class MonitorService implements IMonitorService {
|
||||
this.checksRepository = checksRepository;
|
||||
this.monitorStatsRepository = monitorStatsRepository;
|
||||
this.statusPagesRepository = statusPagesRepository;
|
||||
this.incidentsRepository = incidentsRepository;
|
||||
}
|
||||
|
||||
get serviceName(): string {
|
||||
@@ -418,6 +428,15 @@ export class MonitorService implements IMonitorService {
|
||||
stack: err.stack,
|
||||
});
|
||||
});
|
||||
|
||||
await this.incidentsRepository.deleteByMonitorId(monitor.id, teamId).catch((err: any) => {
|
||||
this.logger.warn({
|
||||
message: `Error deleting incidents for monitor ${monitor.id} with name ${monitor.name}`,
|
||||
service: SERVICE_NAME,
|
||||
stack: err.stack,
|
||||
});
|
||||
});
|
||||
|
||||
await this.jobQueue.deleteJob(monitor);
|
||||
return monitor;
|
||||
};
|
||||
|
||||
@@ -153,6 +153,25 @@ class SuperSimpleQueueHelper {
|
||||
};
|
||||
};
|
||||
|
||||
getCleanupOrphanedJob = () => {
|
||||
return async () => {
|
||||
try {
|
||||
// Remove orphaned monitors
|
||||
// remove orphaned monitorStats
|
||||
// Remove orphaned checks
|
||||
// Remove orphaned incidents
|
||||
} catch (error: any) {
|
||||
this.logger.warn({
|
||||
message: error.message,
|
||||
service: SERVICE_NAME,
|
||||
method: "getCleanupOrphanedJob",
|
||||
stack: error.stack,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
async isInMaintenanceWindow(monitorId: string, teamId: string) {
|
||||
const maintenanceWindows = await this.maintenanceWindowsRepository.findByMonitorId(monitorId, teamId);
|
||||
// Check for active maintenance window:
|
||||
|
||||
Reference in New Issue
Block a user