11const got = ( ...args ) => import ( 'got' ) . then ( ( { default : got } ) => got ( ...args ) ) ;
2+ const config = require ( 'config' ) ;
23const { Mutex, withTimeout, E_TIMEOUT } = require ( 'async-mutex' ) ;
34const apiKeys = require ( './apiKey' ) ;
45const path = require ( "path" ) ;
@@ -7,24 +8,20 @@ const logger = require('../logger').logger;
78const GET_LOCATIONS = 'http://www.webpagetest.org/getLocations.php?f=json' ;
89
910class LocationSelector {
10- CACHE_TTL = 10 ;
11- DEFAULT_LOCATION = 'IAD_US_01' ;
12- UPDATE_LOCATIONS_TIMEOUT = 20 ;
13-
1411 constructor ( ) {
1512 if ( ! LocationSelector . instance ) {
1613 this . cachedAllLocations = [ ] ;
17- this . location = this . DEFAULT_LOCATION ;
14+ this . location = config . get ( 'locationSelector.locationSelector.defaultLocation' ) ;
1815 this . lastUpdated = null ;
19- this . mutex = withTimeout ( new Mutex ( ) , this . UPDATE_LOCATIONS_TIMEOUT * 1000 ) ;
16+ this . mutex = withTimeout ( new Mutex ( ) , config . get ( 'locationSelector.locationSelector.updateTimeout' ) * 1000 ) ;
2017 LocationSelector . instance = this ;
2118 }
2219 return LocationSelector . instance ;
2320 }
2421
2522 isExpired ( ) {
2623 const now = Date . now ( ) ;
27- return ( ! this . lastUpdated || ( now - this . lastUpdated ) > this . CACHE_TTL * 1000 ) ;
24+ return ( ! this . lastUpdated || ( now - this . lastUpdated ) > config . get ( 'locationSelector.locationSelector.cacheTtl' ) * 1000 ) ;
2825 }
2926
3027 async fetchLocations ( ) {
@@ -136,5 +133,4 @@ class LocationSelector {
136133}
137134
138135const instance = new LocationSelector ( ) ;
139-
140136module . exports = instance ;
0 commit comments