@@ -396,23 +396,26 @@ export abstract class HttpProvider {
396
396
export class Heart {
397
397
private heartbeatTimer ?: NodeJS . Timeout
398
398
private heartbeatInterval = 60000
399
- private lastHeartbeat = 0
399
+ public lastHeartbeat = 0
400
400
401
401
public constructor ( private readonly heartbeatPath : string , private readonly isActive : ( ) => Promise < boolean > ) { }
402
402
403
+ public alive ( ) : boolean {
404
+ const now = Date . now ( )
405
+ return now - this . lastHeartbeat < this . heartbeatInterval
406
+ }
403
407
/**
404
408
* Write to the heartbeat file if we haven't already done so within the
405
409
* timeout and start or reset a timer that keeps running as long as there is
406
410
* activity. Failures are logged as warnings.
407
411
*/
408
412
public beat ( ) : void {
409
- const now = Date . now ( )
410
- if ( now - this . lastHeartbeat >= this . heartbeatInterval ) {
413
+ if ( ! this . alive ( ) ) {
411
414
logger . trace ( "heartbeat" )
412
415
fs . outputFile ( this . heartbeatPath , "" ) . catch ( ( error ) => {
413
416
logger . warn ( error . message )
414
417
} )
415
- this . lastHeartbeat = now
418
+ this . lastHeartbeat = Date . now ( )
416
419
if ( typeof this . heartbeatTimer !== "undefined" ) {
417
420
clearTimeout ( this . heartbeatTimer )
418
421
}
@@ -457,7 +460,7 @@ export class HttpServer {
457
460
private listenPromise : Promise < string | null > | undefined
458
461
public readonly protocol : "http" | "https"
459
462
private readonly providers = new Map < string , HttpProvider > ( )
460
- private readonly heart : Heart
463
+ public readonly heart : Heart
461
464
private readonly socketProvider = new SocketProxyProvider ( )
462
465
463
466
/**
@@ -602,8 +605,10 @@ export class HttpServer {
602
605
}
603
606
604
607
private onRequest = async ( request : http . IncomingMessage , response : http . ServerResponse ) : Promise < void > => {
605
- this . heart . beat ( )
606
608
const route = this . parseUrl ( request )
609
+ if ( route . providerBase !== "/healthz" ) {
610
+ this . heart . beat ( )
611
+ }
607
612
const write = ( payload : HttpResponse ) : void => {
608
613
response . writeHead ( payload . redirect ? HttpCode . Redirect : payload . code || HttpCode . Ok , {
609
614
"Content-Type" : payload . mime || getMediaMime ( payload . filePath ) ,
0 commit comments