Skip to content

Commit 32b54dd

Browse files
authored
Merge pull request #2882 from bluewave-labs/feat/migration
add migration for statusWindowThreshold
2 parents 1c3c5f4 + f8a0741 commit 32b54dd

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

server/src/db/mongo/MongoDB.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import mongoose from "mongoose";
22
import AppSettings from "../models/AppSettings.js";
3-
3+
import { runMigrations } from "./migration/index.js";
44
class MongoDB {
55
static SERVICE_NAME = "MongoDB";
66

@@ -65,6 +65,8 @@ class MongoDB {
6565
service: this.SERVICE_NAME,
6666
method: "connect",
6767
});
68+
69+
await runMigrations();
6870
} catch (error) {
6971
this.logger.error({
7072
message: error.message,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Monitor from "../../models/Monitor.js";
2+
async function migrateStatusWindowThreshold() {
3+
try {
4+
const monitors = await Monitor.find({ statusWindowThreshold: { $lt: 1 } });
5+
for (const monitor of monitors) {
6+
monitor.statusWindowThreshold = monitor.statusWindowThreshold * 100;
7+
await monitor.save();
8+
console.log(`Migrated monitor ${monitor._id}: statusWindowThreshold set to ${monitor.statusWindowThreshold}`);
9+
}
10+
console.log("StatusWindowThreshold migration complete.");
11+
return true;
12+
} catch (err) {
13+
console.error("Migration error:", err);
14+
return false;
15+
}
16+
}
17+
18+
export { migrateStatusWindowThreshold };
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { migrateStatusWindowThreshold } from "./0001_migrateStatusWindowThreshold.js";
2+
3+
const runMigrations = async () => {
4+
await migrateStatusWindowThreshold();
5+
};
6+
7+
export { runMigrations };

server/src/service/infrastructure/statusService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class StatusService {
158158
statusChanged = true;
159159
}
160160
// If the failure rate is below the threshold and the monitor is down, recover:
161-
else if (failureRate <= monitor.statusWindowThreshold && monitor.status === false) {
161+
else if (failureRate < monitor.statusWindowThreshold && monitor.status === false) {
162162
newStatus = true;
163163
statusChanged = true;
164164
}

0 commit comments

Comments
 (0)