@@ -23,9 +23,9 @@ const logger = newLogger("HealthCheck");
2323
2424const fireHealthCheck = function (
2525 config : BotConfig ,
26- url : string ,
27- method : Method | undefined ,
28- bearerToken : string | undefined ,
26+ urls : ReadonlyArray < string > ,
27+ methods : ReadonlyArray < Method > ,
28+ bearerTokens : ReadonlyArray < string > ,
2929) {
3030 // Check that AAPL returns some data.
3131 // If it does, we are live and working
@@ -42,15 +42,13 @@ const fireHealthCheck = function (
4242 oldCommand : undefined ,
4343 } ) ;
4444
45- try {
46- let success : boolean ;
47- if ( check && ! check . error ) {
48- logger . log ( `AAPL success, attempt healthcheck: ${ url } ` ) ;
49- success = true ;
50- } else {
51- logger . log ( `AAPL failure, attempt healthcheck: ${ url } ` ) ;
52- success = false ;
53- }
45+ const success = ! ! ( check && ! check . error ) ;
46+
47+ const work : Promise < unknown > [ ] = [ ] ;
48+ for ( let i = 0 ; i < urls . length ; ++ i ) {
49+ const url = urls [ i ] ;
50+ const method = methods [ i ] ;
51+ const bearerToken = bearerTokens [ i ] ;
5452
5553 let headers : RawAxiosRequestHeaders | undefined = undefined ;
5654 if ( bearerToken ) {
@@ -59,40 +57,49 @@ const fireHealthCheck = function (
5957 } ;
6058 }
6159
62- await axios ( {
63- // If undefined, will be axios default "get"
64- method,
65- headers,
66- url : `${ url } ?success=${ success } ` ,
67- } ) ;
68- } catch ( e ) {
69- // Health check error, try again later
70- // Maybe network is offline?
71- logger . error ( `Healthcheck failed!` , e ) ;
60+ work . push (
61+ Promise . resolve ( ) . then ( async ( ) => {
62+ try {
63+ await axios ( {
64+ // If undefined, will be axios default "get"
65+ method,
66+ headers,
67+ url : `${ url } ?success=${ success } ` ,
68+ } ) ;
69+ } catch ( e ) {
70+ // Health check error, try again later
71+ // Maybe network is offline?
72+ logger . error ( `Healthcheck report failed!` , url , success , e ) ;
73+ }
74+ } ) ,
75+ ) ;
7276 }
77+
78+ await Promise . all ( work ) ;
7379 } ) ;
7480} ;
7581
7682export const registerPeriodicHealthCheck = function ( config : BotConfig ) {
7783 let timer : NodeJS . Timeout | undefined = undefined ;
7884
79- const { healthCheckMethod, healthCheckUrl, healthCheckBearerToken } = config ;
85+ const { healthCheckUrls, healthCheckMethods, healthCheckBearerTokens } =
86+ config ;
8087
81- if ( healthCheckUrl ) {
88+ if ( healthCheckUrls . length > 0 ) {
8289 timer = setInterval ( ( ) => {
8390 fireHealthCheck (
8491 config ,
85- healthCheckUrl ,
86- healthCheckMethod ,
87- healthCheckBearerToken ,
92+ healthCheckUrls ,
93+ healthCheckMethods ,
94+ healthCheckBearerTokens ,
8895 ) ;
8996 } , 60 * 1000 ) ;
9097
9198 fireHealthCheck (
9299 config ,
93- healthCheckUrl ,
94- healthCheckMethod ,
95- healthCheckBearerToken ,
100+ healthCheckUrls ,
101+ healthCheckMethods ,
102+ healthCheckBearerTokens ,
96103 ) ;
97104 }
98105
0 commit comments