@@ -11,9 +11,31 @@ import {
1111 sendCoinrankListV2 ,
1212 sendCoinranksV2
1313} from './legacyRouter'
14- import { heartbeatV3 , ratesV3 } from './router'
14+ import { initializeCoingeckoSyncDocs } from './providers/coingecko/coingecko'
15+ import { initializeCoinmarketcapSyncDocs } from './providers/coinmarketcap/coinmarketcap'
16+ import { initializeConstantRateSyncDocs } from './providers/constantRates'
17+ import { heartbeatV3 , initializeRouterSyncDocs , ratesV3 } from './router'
1518
1619async function main ( ) : Promise < void > {
20+ // Try to preload synced docs before serving traffic. If some fail, keep
21+ // running in a degraded state and rely on the background sync retries.
22+ console . log ( 'Starting initial sync doc load' )
23+ const syncResults = await Promise . allSettled ( [
24+ initializeRouterSyncDocs ( ) ,
25+ initializeCoingeckoSyncDocs ( ) ,
26+ initializeCoinmarketcapSyncDocs ( ) ,
27+ initializeConstantRateSyncDocs ( )
28+ ] )
29+ const failedSyncs = syncResults . filter (
30+ result => result . status === 'rejected'
31+ ) . length
32+ if ( failedSyncs > 0 ) {
33+ console . warn (
34+ `Initial sync doc load completed with ${ failedSyncs } failure(s); starting in degraded mode`
35+ )
36+ } else {
37+ console . log ( 'Initial sync doc load complete' )
38+ }
1739 server ( )
1840}
1941
@@ -43,7 +65,7 @@ function server(): void {
4365 console . log ( `HTTP v3 server listening on port ${ httpPort } ` )
4466}
4567
46- main ( ) . catch ( error => {
68+ main ( ) . catch ( ( error : unknown ) => {
4769 console . error ( error )
4870 process . exit ( 1 )
4971} )
0 commit comments