@@ -396,23 +396,26 @@ export abstract class HttpProvider {
396396export class Heart {
397397 private heartbeatTimer ?: NodeJS . Timeout
398398 private heartbeatInterval = 60000
399- private lastHeartbeat = 0
399+ public lastHeartbeat = 0
400400
401401 public constructor ( private readonly heartbeatPath : string , private readonly isActive : ( ) => Promise < boolean > ) { }
402402
403+ public alive ( ) : boolean {
404+ const now = Date . now ( )
405+ return now - this . lastHeartbeat < this . heartbeatInterval
406+ }
403407 /**
404408 * Write to the heartbeat file if we haven't already done so within the
405409 * timeout and start or reset a timer that keeps running as long as there is
406410 * activity. Failures are logged as warnings.
407411 */
408412 public beat ( ) : void {
409- const now = Date . now ( )
410- if ( now - this . lastHeartbeat >= this . heartbeatInterval ) {
413+ if ( ! this . alive ( ) ) {
411414 logger . trace ( "heartbeat" )
412415 fs . outputFile ( this . heartbeatPath , "" ) . catch ( ( error ) => {
413416 logger . warn ( error . message )
414417 } )
415- this . lastHeartbeat = now
418+ this . lastHeartbeat = Date . now ( )
416419 if ( typeof this . heartbeatTimer !== "undefined" ) {
417420 clearTimeout ( this . heartbeatTimer )
418421 }
@@ -457,7 +460,7 @@ export class HttpServer {
457460 private listenPromise : Promise < string | null > | undefined
458461 public readonly protocol : "http" | "https"
459462 private readonly providers = new Map < string , HttpProvider > ( )
460- private readonly heart : Heart
463+ public readonly heart : Heart
461464 private readonly socketProvider = new SocketProxyProvider ( )
462465
463466 /**
@@ -602,8 +605,10 @@ export class HttpServer {
602605 }
603606
604607 private onRequest = async ( request : http . IncomingMessage , response : http . ServerResponse ) : Promise < void > => {
605- this . heart . beat ( )
606608 const route = this . parseUrl ( request )
609+ if ( route . providerBase !== "/healthz" ) {
610+ this . heart . beat ( )
611+ }
607612 const write = ( payload : HttpResponse ) : void => {
608613 response . writeHead ( payload . redirect ? HttpCode . Redirect : payload . code || HttpCode . Ok , {
609614 "Content-Type" : payload . mime || getMediaMime ( payload . filePath ) ,
0 commit comments