Skip to content

Commit 739080f

Browse files
committed
chore: use mean max uptime
1 parent 108c27f commit 739080f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main/global/UptimeChecker.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,26 @@ import { dep } from 'mesh-ioc';
66

77
export 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+
}

0 commit comments

Comments
 (0)