@@ -357,7 +357,7 @@ class SystemStore extends EventEmitter {
357
357
this . START_REFRESH_THRESHOLD = 10 * 60 * 1000 ;
358
358
this . FORCE_REFRESH_THRESHOLD = 60 * 60 * 1000 ;
359
359
this . SYSTEM_STORE_LOAD_CONCURRENCY = config . SYSTEM_STORE_LOAD_CONCURRENCY || 5 ;
360
- this . source = ( process . env . HOSTNAME && process . env . HOSTNAME . indexOf ( "endpoint" ) === - 1 ) ? SOURCE . DB : SOURCE . CORE ;
360
+ this . source = config . SYSTEM_STORE_SOURCE . toLocaleLowerCase ( ) === 'core' ? SOURCE . CORE : SOURCE . DB ;
361
361
dbg . log0 ( "system store source is" , this . source ) ;
362
362
this . _load_serial = new semaphore . Semaphore ( 1 , { warning_timeout : this . START_REFRESH_THRESHOLD } ) ;
363
363
for ( const col of COLLECTIONS ) {
@@ -431,11 +431,20 @@ class SystemStore extends EventEmitter {
431
431
const new_data = new SystemStoreData ( ) ;
432
432
let millistamp = time_utils . millistamp ( ) ;
433
433
await this . _register_for_changes ( ) ;
434
- if ( this . source === SOURCE . DB ) {
434
+ let from_core_failure = false ;
435
+
436
+ if ( this . source === SOURCE . CORE ) {
437
+ try {
438
+ this . data = new SystemStoreData ( ) ;
439
+ await this . _read_new_data_from_core ( this . data ) ;
440
+ } catch ( e ) {
441
+ dbg . error ( "Failed to load system store from core. Will load from db." , e ) ;
442
+ from_core_failure = true ;
443
+ }
444
+ }
445
+
446
+ if ( this . source === SOURCE . DB || from_core_failure ) {
435
447
await this . _read_new_data_from_db ( new_data ) ;
436
- } else {
437
- this . data = new SystemStoreData ( ) ;
438
- await this . _read_new_data_from_core ( this . data ) ;
439
448
}
440
449
441
450
const secret = await os_utils . read_server_secret ( ) ;
@@ -447,7 +456,7 @@ class SystemStore extends EventEmitter {
447
456
depth : 4
448
457
} ) ) ;
449
458
}
450
- if ( this . source === SOURCE . DB ) {
459
+ if ( this . source === SOURCE . DB || from_core_failure ) {
451
460
this . old_db_data = this . _update_data_from_new ( this . old_db_data || { } , new_data ) ;
452
461
this . data = _ . cloneDeep ( this . old_db_data ) ;
453
462
}
0 commit comments