initial commit
This commit is contained in:
1 parent
7cb985116e
commit
75acf7b38f
955 files changed
+37333
-87054
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import { Monitor, MonitorStats } from "@/db/models/index.js";
|
||||
import { getChildLogger } from "@/logger/Logger.js";
|
||||
|
||||
const SERVICE_NAME = "MonitorStatsService";
|
||||
const logger = getChildLogger(SERVICE_NAME);
|
||||
export interface IMonitorStatsService {
|
||||
cleanupOrphanedMonitorStats: () => Promise<boolean>;
|
||||
}
|
||||
|
||||
class MonitorStatsService implements IMonitorStatsService {
|
||||
public SERVICE_NAME: string;
|
||||
constructor() {
|
||||
this.SERVICE_NAME = SERVICE_NAME;
|
||||
}
|
||||
|
||||
async cleanupOrphanedMonitorStats() {
|
||||
try {
|
||||
const monitorIds = await Monitor.find().distinct("_id");
|
||||
const result = await MonitorStats.deleteMany({
|
||||
monitorId: { $nin: monitorIds },
|
||||
});
|
||||
logger.info(`Deleted ${result.deletedCount} orphaned MonitorStats.`);
|
||||
return true;
|
||||
} catch (error) {
|
||||
logger.error("Error cleaning up orphaned MonitorStats:", error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default MonitorStatsService;
|
||||
Reference in new issue
Block a user