@@ -4,6 +4,8 @@ import { SchedulerRegistry } from '@nestjs/schedule';
44import { isDefined } from 'class-validator' ;
55
66import { MinigraphStatus } from '../config.entity.js' ;
7+ import { ONE_MINUTE_MS , THREE_MINUTES_MS } from '../helpers/consts.js' ;
8+ import { DynamicRemoteAccessStateService } from '../remote-access/dynamic-remote-access-state.service.js' ;
79import { MothershipConnectionService } from './connection.service.js' ;
810import { MothershipSubscriptionHandler } from './mothership-subscription.handler.js' ;
911
@@ -12,26 +14,23 @@ export class TimeoutCheckerJob {
1214 constructor (
1315 private readonly connectionService : MothershipConnectionService ,
1416 private readonly subscriptionHandler : MothershipSubscriptionHandler ,
15- private schedulerRegistry : SchedulerRegistry
17+ private schedulerRegistry : SchedulerRegistry ,
18+ private readonly dynamicRemoteAccess : DynamicRemoteAccessStateService
1619 ) { }
1720
1821 public jobName = 'connect-timeout-checker' ;
1922 private readonly logger = new Logger ( TimeoutCheckerJob . name ) ;
20- private THREE_MINUTES_MS = 3 * 60 * 1000 ;
21- private ONE_MINUTE_MS = 60 * 1000 ;
2223
2324 private hasMothershipClientTimedOut ( ) {
2425 const { lastPing, status } = this . connectionService . getConnectionState ( ) ?? { } ;
2526 return (
26- status === MinigraphStatus . CONNECTED &&
27- lastPing &&
28- Date . now ( ) - lastPing > this . THREE_MINUTES_MS
27+ status === MinigraphStatus . CONNECTED && lastPing && Date . now ( ) - lastPing > THREE_MINUTES_MS
2928 ) ;
3029 }
3130
3231 private checkMothershipClientTimeout ( ) {
3332 if ( this . hasMothershipClientTimedOut ( ) ) {
34- const minutes = this . msToMinutes ( this . THREE_MINUTES_MS ) ;
33+ const minutes = this . msToMinutes ( THREE_MINUTES_MS ) ;
3534 this . logger . warn ( `NO PINGS RECEIVED IN ${ minutes } MINUTES, SOCKET MUST BE RECONNECTED` ) ;
3635 this . connectionService . setConnectionStatus ( {
3736 status : MinigraphStatus . PING_FAILURE ,
@@ -43,21 +42,17 @@ export class TimeoutCheckerJob {
4342 private msToMinutes ( ms : number ) {
4443 return ms / 1000 / 60 ;
4544 }
46-
47- private checkRemoteAccessTimeout ( ) {
48- // todo: implement
49- }
50-
45+
5146 async checkForTimeouts ( ) {
52- this . subscriptionHandler . clearStaleSubscriptions ( { maxAgeMs : this . THREE_MINUTES_MS } ) ;
47+ this . subscriptionHandler . clearStaleSubscriptions ( { maxAgeMs : THREE_MINUTES_MS } ) ;
5348 this . checkMothershipClientTimeout ( ) ;
54- this . checkRemoteAccessTimeout ( ) ;
49+ this . dynamicRemoteAccess . checkForTimeout ( ) ;
5550 }
5651
5752 start ( ) {
5853 this . stop ( ) ;
5954 const callback = ( ) => this . checkForTimeouts ( ) ;
60- const interval = setInterval ( callback , this . ONE_MINUTE_MS ) ;
55+ const interval = setInterval ( callback , ONE_MINUTE_MS ) ;
6156 this . schedulerRegistry . addInterval ( this . jobName , interval ) ;
6257 }
6358
0 commit comments