3
3
// See: https://github.com/navikt/nav-enonicxp-frontend-revalidator-proxy
4
4
import { networkInterfaces } from 'os' ;
5
5
import { logger } from 'srcCommon/logger' ;
6
- import { getRenderCacheKeyPrefix , getResponseCacheKeyPrefix } from 'srcCommon/redis' ;
7
6
import { objectToQueryString } from 'srcCommon/fetch-utils' ;
7
+ import { redisCache } from 'cache/page-cache-handler' ;
8
8
9
9
const { ENV , NODE_ENV , DOCKER_HOST_ADDRESS , REVALIDATOR_PROXY_ORIGIN , SERVICE_SECRET } =
10
10
process . env ;
@@ -22,31 +22,26 @@ const getPodAddress = () => {
22
22
const podAddress = nets ?. eth0 ?. [ 0 ] ?. address ;
23
23
24
24
if ( ! podAddress ) {
25
- logger . error (
26
- 'Error: pod IP address could not be determined' +
27
- ' - Event driven cache regeneration will not be active for this instance'
28
- ) ;
25
+ logger . error ( 'Error: pod IP address could not be determined!' ) ;
29
26
return null ;
30
27
}
31
28
32
29
return podAddress ;
33
30
} ;
34
31
35
- const getProxyLivenessUrl = ( buildId : string ) => {
32
+ const getProxyLivenessUrl = ( ) => {
36
33
const podAddress = getPodAddress ( ) ;
37
34
return podAddress
38
35
? `${ REVALIDATOR_PROXY_ORIGIN } /liveness${ objectToQueryString ( {
39
36
address : podAddress ,
40
- redisPrefixes : [ getRenderCacheKeyPrefix ( buildId ) , getResponseCacheKeyPrefix ( ) ] . join (
41
- ','
42
- ) ,
37
+ redisPrefixes : redisCache . getKeyPrefixes ( ) . join ( ',' ) ,
43
38
} ) } `
44
39
: null ;
45
40
} ;
46
41
47
42
let didStart = false ;
48
43
49
- export const initRevalidatorProxyHeartbeat = ( buildId : string ) => {
44
+ export const initRevalidatorProxyHeartbeat = ( ) => {
50
45
if ( NODE_ENV === 'development' ) {
51
46
return ;
52
47
}
@@ -56,16 +51,17 @@ export const initRevalidatorProxyHeartbeat = (buildId: string) => {
56
51
return ;
57
52
}
58
53
59
- const url = getProxyLivenessUrl ( buildId ) ;
60
- if ( ! url ) {
61
- return ;
62
- }
63
-
64
54
didStart = true ;
65
55
66
56
logger . info ( 'Starting heartbeat loop' ) ;
67
57
68
58
const heartbeatFunc = ( ) => {
59
+ const url = getProxyLivenessUrl ( ) ;
60
+ if ( ! url ) {
61
+ logger . error ( 'Failed to determine revalidator heartbeat url!' ) ;
62
+ return ;
63
+ }
64
+
69
65
fetch ( url , {
70
66
headers : { secret : SERVICE_SECRET } ,
71
67
} ) . catch ( ( e ) => logger . error ( `Failed to send heartbeat signal - ${ e } ` ) ) ;
0 commit comments