From 174346ea2ff6e5f5c85e1b5c10a91af74d4c9f02 Mon Sep 17 00:00:00 2001 From: Boki Date: Mon, 16 Jun 2025 22:19:56 -0400 Subject: [PATCH] got symbols and exchanges working with sessions --- apps/data-service/src/providers/qm.tasks.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/apps/data-service/src/providers/qm.tasks.ts b/apps/data-service/src/providers/qm.tasks.ts index eb3c73c..6c482f3 100644 --- a/apps/data-service/src/providers/qm.tasks.ts +++ b/apps/data-service/src/providers/qm.tasks.ts @@ -60,11 +60,18 @@ export async function createSessions(): Promise { } logger.info('Creating QM sessions...'); for (const [sessionId, sessionArray] of Object.entries(sessionCache)) { - // remove any sessions with failedCalls > 10 - // const filteredArray = sessionArray.filter(session => session.failedCalls <= 10); - // sessionCache[sessionId] = filteredArray; - // if sessionArray is empty or has less than 5 sessions, create a new session - while (sessionArray.length < 2) { + const initialCount = sessionArray.length; + const filteredArray = sessionArray.filter(session => session.failedCalls <= 10); + sessionCache[sessionId] = filteredArray; + + const removedCount = initialCount - filteredArray.length; + if (removedCount > 0) { + logger.info( + `Removed ${removedCount} sessions with excessive failures for ${sessionId}. Remaining: ${filteredArray.length}` + ); + } + + while (sessionCache[sessionId].length < 5) { logger.info(`Creating new session for ${sessionId}`); const proxy = getProxy(); if (proxy === null) { @@ -103,10 +110,10 @@ export async function createSessions(): Promise { logger.info('QM session created successfully', { sessionId, sessionData, + sessionCount: sessionCache[sessionId].length + 1, }); newSession.headers['Datatool-Token'] = sessionData.token; - console.log(newSession.headers); - sessionArray.push(newSession); + sessionCache[sessionId].push(newSession); } } return undefined;