File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -6,19 +6,26 @@ import { dep } from 'mesh-ioc';
66
77export class UptimeChecker {
88
9- @config ( { default : 24 * 60 * 60 } ) MAX_UPTIME_SECONDS ! : number ;
9+ @config ( { default : 24 * 60 * 60 } ) MAX_MEAN_UPTIME_SECONDS ! : number ;
1010
1111 @dep ( ) private logger ! : Logger ;
1212
1313 startedAt = Date . now ( ) ;
1414
15+ // The actual uptime is calculated as +/- 25% of configured mean uptime
16+ maxUptimeMs = randomRange ( .75 , 1.25 ) * this . MAX_MEAN_UPTIME_SECONDS * 1000 ;
17+
1518 @statusCheck ( )
1619 checkUptime ( ) {
17- if ( Date . now ( ) > this . startedAt + this . MAX_UPTIME_SECONDS * 1000 ) {
20+ if ( Date . now ( ) > this . startedAt + this . maxUptimeMs ) {
1821 this . logger . warn ( 'Max uptime reached' ) ;
1922 throw new ServerError ( 'Max uptime reached' ) ;
2023 }
2124 return 'ok' ;
2225 }
2326
2427}
28+
29+ function randomRange ( min : number , max : number ) {
30+ return Math . random ( ) * ( max - min ) + min ;
31+ }
You can’t perform that action at this time.
0 commit comments