update, pause
This commit is contained in:
1 parent
e7e4ce7f57
commit
6b5fd8d17f
9 files changed
+53
-27
No files matched your search
@@ -66,7 +66,7 @@ const MonitorDetailsControlHeader = ({
|
|||||||
gap={theme.spacing(2)}
|
gap={theme.spacing(2)}
|
||||||
>
|
>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
key={monitor?._id}
|
key={monitor?.id}
|
||||||
placement="bottom"
|
placement="bottom"
|
||||||
title={tooltipTitle}
|
title={tooltipTitle}
|
||||||
>
|
>
|
||||||
@@ -78,7 +78,7 @@ const MonitorDetailsControlHeader = ({
|
|||||||
startIcon={<EmailIcon />}
|
startIcon={<EmailIcon />}
|
||||||
disabled={isTestNotificationsDisabled}
|
disabled={isTestNotificationsDisabled}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
testAllNotifications({ monitorId: monitor?._id });
|
testAllNotifications({ monitorId: monitor?.id });
|
||||||
}}
|
}}
|
||||||
sx={{
|
sx={{
|
||||||
whiteSpace: "nowrap",
|
whiteSpace: "nowrap",
|
||||||
@@ -92,7 +92,7 @@ const MonitorDetailsControlHeader = ({
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
color="secondary"
|
color="secondary"
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
navigate(`/incidents/${monitor?._id}`);
|
navigate(`/incidents/${monitor?.id}`);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{t("menu.incidents")}
|
{t("menu.incidents")}
|
||||||
@@ -107,7 +107,7 @@ const MonitorDetailsControlHeader = ({
|
|||||||
}
|
}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
pauseMonitor({
|
pauseMonitor({
|
||||||
monitorId: monitor?._id,
|
monitorId: monitor?.id,
|
||||||
triggerUpdate,
|
triggerUpdate,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
@@ -120,7 +120,7 @@ const MonitorDetailsControlHeader = ({
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
color="secondary"
|
color="secondary"
|
||||||
startIcon={<SettingsOutlinedIcon />}
|
startIcon={<SettingsOutlinedIcon />}
|
||||||
onClick={() => navigate(`/${path}/configure/${monitor._id}`)}
|
onClick={() => navigate(`/${path}/configure/${monitor.id}`)}
|
||||||
>
|
>
|
||||||
Configure
|
Configure
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -387,7 +387,7 @@ export const useUpdateMonitor = () => {
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
await networkService.updateMonitor({
|
await networkService.updateMonitor({
|
||||||
monitorId: monitor._id,
|
monitorId: monitor.id,
|
||||||
updatedFields,
|
updatedFields,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ const UptimeCreate = ({ isClone = false }) => {
|
|||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
form = {
|
form = {
|
||||||
_id: monitor._id,
|
id: monitor.id,
|
||||||
url: monitor.url,
|
url: monitor.url,
|
||||||
name: monitor.name || monitor.url.substring(0, 50),
|
name: monitor.name || monitor.url.substring(0, 50),
|
||||||
statusWindowSize: monitor.statusWindowSize,
|
statusWindowSize: monitor.statusWindowSize,
|
||||||
@@ -287,7 +287,7 @@ const UptimeCreate = ({ isClone = false }) => {
|
|||||||
|
|
||||||
const handleRemove = async (event) => {
|
const handleRemove = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const TEMP_MONITOR = { id: monitor._id };
|
const TEMP_MONITOR = { id: monitor.id };
|
||||||
await deleteMonitor({ monitor: TEMP_MONITOR, redirect: "/uptime" });
|
await deleteMonitor({ monitor: TEMP_MONITOR, redirect: "/uptime" });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ const loginCredentials = joi.object({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const monitorValidation = joi.object({
|
const monitorValidation = joi.object({
|
||||||
_id: joi.string(),
|
id: joi.string(),
|
||||||
userId: joi.string(),
|
userId: joi.string(),
|
||||||
teamId: joi.string(),
|
teamId: joi.string(),
|
||||||
statusWindowSize: joi.number().min(1).max(20).default(5).messages({
|
statusWindowSize: joi.number().min(1).max(20).default(5).messages({
|
||||||
|
|||||||
@@ -184,18 +184,13 @@ class MongoChecksRepository implements IChecksRepository {
|
|||||||
}
|
}
|
||||||
const mongoIds = monitorIds.map((id) => new mongoose.Types.ObjectId(id));
|
const mongoIds = monitorIds.map((id) => new mongoose.Types.ObjectId(id));
|
||||||
const limitPerMonitor = options?.limitPerMonitor ?? 25;
|
const limitPerMonitor = options?.limitPerMonitor ?? 25;
|
||||||
const maxIntervalMs = Number(10 * 60 * 1000);
|
|
||||||
const bufferMs = Number(maxIntervalMs);
|
|
||||||
const lookbackMs = limitPerMonitor * maxIntervalMs + bufferMs;
|
|
||||||
|
|
||||||
const cutoffDate = new Date(Date.now() - lookbackMs);
|
|
||||||
const checkGroups = await CheckModel.aggregate([
|
const checkGroups = await CheckModel.aggregate([
|
||||||
{
|
{
|
||||||
$match: {
|
$match: {
|
||||||
"metadata.monitorId": { $in: mongoIds },
|
"metadata.monitorId": { $in: mongoIds },
|
||||||
createdAt: { $gte: cutoffDate },
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{ $sort: { "metadata.monitorId": 1, createdAt: -1 } },
|
||||||
{
|
{
|
||||||
$group: {
|
$group: {
|
||||||
_id: "$metadata.monitorId",
|
_id: "$metadata.monitorId",
|
||||||
|
|||||||
@@ -24,8 +24,10 @@ export interface IMonitorsRepository {
|
|||||||
// collection fetch
|
// collection fetch
|
||||||
findAll(): Promise<Monitor[] | null>;
|
findAll(): Promise<Monitor[] | null>;
|
||||||
findByTeamId(teamId: string, config: TeamQueryConfig): Promise<Monitor[] | null>;
|
findByTeamId(teamId: string, config: TeamQueryConfig): Promise<Monitor[] | null>;
|
||||||
|
|
||||||
// update
|
// update
|
||||||
update(monitorId: string, updates: Partial<Monitor>): Promise<Monitor>;
|
updateById(monitorId: string, updates: Partial<Monitor>): Promise<Monitor>;
|
||||||
|
togglePauseById(monitorId: string, teamId: string): Promise<Monitor>;
|
||||||
// delete
|
// delete
|
||||||
deleteByTeamId(teamId: string): Promise<{ monitors: Monitor[]; deletedCount: number }>;
|
deleteByTeamId(teamId: string): Promise<{ monitors: Monitor[]; deletedCount: number }>;
|
||||||
|
|
||||||
@@ -34,4 +36,5 @@ export interface IMonitorsRepository {
|
|||||||
|
|
||||||
// other
|
// other
|
||||||
findMonitorsSummaryByTeamId(teamId: string, config?: SummaryConfig): Promise<any>;
|
findMonitorsSummaryByTeamId(teamId: string, config?: SummaryConfig): Promise<any>;
|
||||||
|
findGroupsByTeamId(teamId: string): Promise<string[]>;
|
||||||
}
|
}
|
||||||
@@ -96,7 +96,7 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
return count;
|
return count;
|
||||||
};
|
};
|
||||||
|
|
||||||
update = async (monitorId: string, patch: Partial<Monitor>) => {
|
updateById = async (monitorId: string, patch: Partial<Monitor>) => {
|
||||||
const updatedMonitor = await MonitorModel.findOneAndUpdate(
|
const updatedMonitor = await MonitorModel.findOneAndUpdate(
|
||||||
{ _id: monitorId },
|
{ _id: monitorId },
|
||||||
{
|
{
|
||||||
@@ -112,6 +112,25 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
return this.toEntity(updatedMonitor);
|
return this.toEntity(updatedMonitor);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
togglePauseById = async (monitorId: string, teamId: string) => {
|
||||||
|
const monitor = await MonitorModel.findOneAndUpdate(
|
||||||
|
{ _id: monitorId, teamId },
|
||||||
|
[
|
||||||
|
{
|
||||||
|
$set: {
|
||||||
|
isActive: { $not: "$isActive" },
|
||||||
|
status: "$$REMOVE",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
if (!monitor) {
|
||||||
|
throw new AppError({ message: `Monitor with ID ${monitorId} not found for the given team.`, status: 404 });
|
||||||
|
}
|
||||||
|
return this.toEntity(monitor);
|
||||||
|
};
|
||||||
|
|
||||||
deleteByTeamId = async (teamId: string) => {
|
deleteByTeamId = async (teamId: string) => {
|
||||||
const monitors = await MonitorModel.find({ teamId });
|
const monitors = await MonitorModel.find({ teamId });
|
||||||
const { deletedCount } = await MonitorModel.deleteMany({ teamId });
|
const { deletedCount } = await MonitorModel.deleteMany({ teamId });
|
||||||
@@ -157,6 +176,14 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
return summary ?? { totalMonitors: 0, upMonitors: 0, downMonitors: 0, pausedMonitors: 0 };
|
return summary ?? { totalMonitors: 0, upMonitors: 0, downMonitors: 0, pausedMonitors: 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
findGroupsByTeamId = async (teamId: string): Promise<string[]> => {
|
||||||
|
const groups = await MonitorModel.distinct("group", {
|
||||||
|
teamId: new mongoose.Types.ObjectId(teamId),
|
||||||
|
group: { $nin: [null, ""] },
|
||||||
|
});
|
||||||
|
return groups.sort();
|
||||||
|
};
|
||||||
|
|
||||||
private mapDocuments = (documents: MonitorDocument[]): Monitor[] => {
|
private mapDocuments = (documents: MonitorDocument[]): Monitor[] => {
|
||||||
if (!documents?.length) {
|
if (!documents?.length) {
|
||||||
return [];
|
return [];
|
||||||
|
|||||||
@@ -48,10 +48,10 @@ export interface IMonitorService {
|
|||||||
explain?: boolean;
|
explain?: boolean;
|
||||||
}): Promise<{ summary: any; count: number; monitors: any[] }>;
|
}): Promise<{ summary: any; count: number; monitors: any[] }>;
|
||||||
getAllGames(): any;
|
getAllGames(): any;
|
||||||
getGroupsByTeamId(args: { teamId: string }): Promise<any[]>;
|
getGroupsByTeamId(args: { teamId: string }): Promise<string[]>;
|
||||||
|
|
||||||
// update
|
// update
|
||||||
editMonitor(args: { teamId: string; monitorId: string; body: any }): Promise<void>;
|
editMonitor(args: { teamId: string; monitorId: string; body: Monitor }): Promise<Monitor>;
|
||||||
pauseMonitor(args: { teamId: string; monitorId: string }): Promise<any>;
|
pauseMonitor(args: { teamId: string; monitorId: string }): Promise<any>;
|
||||||
|
|
||||||
// delete
|
// delete
|
||||||
@@ -423,21 +423,22 @@ export class MonitorService implements IMonitorService {
|
|||||||
return this.games;
|
return this.games;
|
||||||
};
|
};
|
||||||
|
|
||||||
getGroupsByTeamId = async ({ teamId }: { teamId: string }): Promise<any[]> => {
|
getGroupsByTeamId = async ({ teamId }: { teamId: string }): Promise<string[]> => {
|
||||||
const groups = await this.db.monitorModule.getGroupsByTeamId({ teamId });
|
const groups = await this.monitorsRepository.findGroupsByTeamId(teamId);
|
||||||
return groups;
|
return groups;
|
||||||
};
|
};
|
||||||
|
|
||||||
editMonitor = async ({ teamId, monitorId, body }: { teamId: string; monitorId: string; body: any }): Promise<void> => {
|
editMonitor = async ({ teamId, monitorId, body }: { teamId: string; monitorId: string; body: Monitor }) => {
|
||||||
await this.verifyTeamAccess({ teamId, monitorId });
|
await this.verifyTeamAccess({ teamId, monitorId });
|
||||||
const editedMonitor = await this.db.monitorModule.editMonitor({ monitorId, body });
|
const editedMonitor = await this.monitorsRepository.updateById(monitorId, body);
|
||||||
await this.jobQueue.updateJob(editedMonitor);
|
await this.jobQueue.updateJob(editedMonitor);
|
||||||
|
return editedMonitor;
|
||||||
};
|
};
|
||||||
|
|
||||||
pauseMonitor = async ({ teamId, monitorId }: { teamId: string; monitorId: string }): Promise<any> => {
|
pauseMonitor = async ({ teamId, monitorId }: { teamId: string; monitorId: string }): Promise<any> => {
|
||||||
await this.verifyTeamAccess({ teamId, monitorId });
|
await this.verifyTeamAccess({ teamId, monitorId });
|
||||||
const monitor = await this.db.monitorModule.pauseMonitor({ monitorId });
|
const monitor = await this.monitorsRepository.togglePauseById(monitorId, teamId);
|
||||||
monitor.isActive === true ? await this.jobQueue.resumeJob(monitor._id, monitor) : await this.jobQueue.pauseJob(monitor);
|
monitor.isActive === true ? await this.jobQueue.resumeJob(monitor) : await this.jobQueue.pauseJob(monitor);
|
||||||
return monitor;
|
return monitor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ class StatusService {
|
|||||||
|
|
||||||
// Return early if not enough data points
|
// Return early if not enough data points
|
||||||
if (monitor.statusWindow.length < monitor.statusWindowSize) {
|
if (monitor.statusWindow.length < monitor.statusWindowSize) {
|
||||||
const updated = await this.monitorsRepository.update(monitor.id, monitor);
|
const updated = await this.monitorsRepository.updateById(monitor.id, monitor);
|
||||||
return {
|
return {
|
||||||
monitor: updated,
|
monitor: updated,
|
||||||
statusChanged: false,
|
statusChanged: false,
|
||||||
@@ -285,7 +285,7 @@ class StatusService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
monitor.status = newStatus;
|
monitor.status = newStatus;
|
||||||
const updated = await this.monitorsRepository.update(monitor.id, monitor);
|
const updated = await this.monitorsRepository.updateById(monitor.id, monitor);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
monitor: updated,
|
monitor: updated,
|
||||||
|
|||||||
Reference in new issue
Block a user