moved proxy redis init to app start
This commit is contained in:
parent
a7ec942916
commit
35b0eb3783
2 changed files with 30 additions and 16 deletions
|
|
@ -105,10 +105,32 @@ async function resetProxyStats(): Promise<void> {
|
|||
return Promise.resolve();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize proxy cache for use during application startup
|
||||
* This should be called before any proxy operations
|
||||
*/
|
||||
export async function initializeProxyCache(): Promise<void> {
|
||||
logger = getLogger('proxy-tasks');
|
||||
cache = createCache({
|
||||
keyPrefix: 'proxy:',
|
||||
ttl: PROXY_CONFIG.CACHE_TTL,
|
||||
enableMetrics: true
|
||||
});
|
||||
|
||||
logger.info('Initializing proxy cache...');
|
||||
await cache.waitForReady(10000);
|
||||
logger.info('Proxy cache initialized successfully');
|
||||
|
||||
// Initialize other shared resources that don't require cache
|
||||
httpClient = new HttpClient({ timeout: 10000 }, logger);
|
||||
concurrencyLimit = pLimit(PROXY_CONFIG.CONCURRENCY_LIMIT);
|
||||
|
||||
logger.info('Proxy tasks initialized');
|
||||
}
|
||||
|
||||
// Initialize shared resources
|
||||
async function initializeSharedResources() {
|
||||
if (!logger) {
|
||||
// If not initialized at startup, initialize with fallback mode
|
||||
logger = getLogger('proxy-tasks');
|
||||
cache = createCache({
|
||||
keyPrefix: 'proxy:',
|
||||
|
|
@ -116,24 +138,10 @@ async function initializeSharedResources() {
|
|||
enableMetrics: true
|
||||
});
|
||||
|
||||
// Always initialize httpClient and concurrencyLimit first
|
||||
httpClient = new HttpClient({ timeout: 10000 }, logger);
|
||||
concurrencyLimit = pLimit(PROXY_CONFIG.CONCURRENCY_LIMIT);
|
||||
|
||||
// Check if cache is ready, but don't block initialization
|
||||
if (cache.isReady()) {
|
||||
logger.info('Cache already ready');
|
||||
} else {
|
||||
logger.info('Cache not ready yet, tasks will use fallback mode');
|
||||
// Try to wait briefly for cache to be ready, but don't block
|
||||
cache.waitForReady(5000).then(() => {
|
||||
logger.info('Cache became ready after initialization');
|
||||
}).catch(error => {
|
||||
logger.warn('Cache connection timeout, continuing with fallback mode:', {error: error.message});
|
||||
});
|
||||
}
|
||||
|
||||
logger.info('Proxy tasks initialized');
|
||||
logger.info('Proxy tasks initialized (fallback mode)');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue