Merge pull request #2882 from bluewave-labs/feat/migration
add migration for statusWindowThreshold
This commit is contained in:
4 files changed
+29
-2
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import AppSettings from "../models/AppSettings.js";
|
import AppSettings from "../models/AppSettings.js";
|
||||||
|
import { runMigrations } from "./migration/index.js";
|
||||||
class MongoDB {
|
class MongoDB {
|
||||||
static SERVICE_NAME = "MongoDB";
|
static SERVICE_NAME = "MongoDB";
|
||||||
|
|
||||||
@@ -65,6 +65,8 @@ class MongoDB {
|
|||||||
service: this.SERVICE_NAME,
|
service: this.SERVICE_NAME,
|
||||||
method: "connect",
|
method: "connect",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await runMigrations();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error({
|
this.logger.error({
|
||||||
message: error.message,
|
message: error.message,
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import Monitor from "../../models/Monitor.js";
|
||||||
|
async function migrateStatusWindowThreshold() {
|
||||||
|
try {
|
||||||
|
const monitors = await Monitor.find({ statusWindowThreshold: { $lt: 1 } });
|
||||||
|
for (const monitor of monitors) {
|
||||||
|
monitor.statusWindowThreshold = monitor.statusWindowThreshold * 100;
|
||||||
|
await monitor.save();
|
||||||
|
console.log(`Migrated monitor ${monitor._id}: statusWindowThreshold set to ${monitor.statusWindowThreshold}`);
|
||||||
|
}
|
||||||
|
console.log("StatusWindowThreshold migration complete.");
|
||||||
|
return true;
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Migration error:", err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { migrateStatusWindowThreshold };
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { migrateStatusWindowThreshold } from "./0001_migrateStatusWindowThreshold.js";
|
||||||
|
|
||||||
|
const runMigrations = async () => {
|
||||||
|
await migrateStatusWindowThreshold();
|
||||||
|
};
|
||||||
|
|
||||||
|
export { runMigrations };
|
||||||
@@ -158,7 +158,7 @@ class StatusService {
|
|||||||
statusChanged = true;
|
statusChanged = true;
|
||||||
}
|
}
|
||||||
// If the failure rate is below the threshold and the monitor is down, recover:
|
// If the failure rate is below the threshold and the monitor is down, recover:
|
||||||
else if (failureRate <= monitor.statusWindowThreshold && monitor.status === false) {
|
else if (failureRate < monitor.statusWindowThreshold && monitor.status === false) {
|
||||||
newStatus = true;
|
newStatus = true;
|
||||||
statusChanged = true;
|
statusChanged = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user