File tree Expand file tree Collapse file tree 4 files changed +29
-2
lines changed
Expand file tree Collapse file tree 4 files changed +29
-2
lines changed Original file line number Diff line number Diff line change 11import mongoose from "mongoose" ;
22import AppSettings from "../models/AppSettings.js" ;
3-
3+ import { runMigrations } from "./migration/index.js" ;
44class 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 ,
Original file line number Diff line number Diff line change 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 } ;
Original file line number Diff line number Diff line change 1+ import { migrateStatusWindowThreshold } from "./0001_migrateStatusWindowThreshold.js" ;
2+
3+ const runMigrations = async ( ) => {
4+ await migrateStatusWindowThreshold ( ) ;
5+ } ;
6+
7+ export { runMigrations } ;
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments