refactoring

This commit is contained in:
Boki 2025-06-22 07:13:09 -04:00
parent 3fb9df425c
commit 62a2f15dab
12 changed files with 670 additions and 13 deletions

View file

@ -18,14 +18,14 @@ export async function checkSessions(handler: BaseHandler): Promise<{
const cleanedCount = sessionManager.cleanupFailedSessions();
// Check which session IDs need more sessions and queue creation jobs
let queuedCount = 0;
for (const sessionId of Object.values(QM_SESSION_IDS)) {
for (const [sessionType, sessionId] of Object.entries(QM_SESSION_IDS)) {
console.log(`Checking session ID: ${sessionId}`);
if (sessionManager.needsMoreSessions(sessionId)) {
const currentCount = sessionManager.getSessions(sessionId).length;
const neededSessions = SESSION_CONFIG.MAX_SESSIONS - currentCount;
for (let i = 0; i < neededSessions; i++) {
await handler.scheduleOperation('create-session', { sessionId });
handler.services.logger.log(`Queued job to create session for ${sessionId}`);
await handler.scheduleOperation('create-session', { sessionId , sessionType });
handler.services.logger.log(`Queued job to create session for ${sessionType}`);
queuedCount++;
}
}
@ -46,20 +46,24 @@ export async function createSingleSession(
input: any
): Promise<{ sessionId: string; status: string; sessionType: string }> {
const { sessionId: sessionType = 'default' } = input || {};
const { sessionId, sessionType } = input || {};
const sessionManager = QMSessionManager.getInstance();
// TODO: Get actual proxy and headers from proxy service
const session = {
// proxy: handler.services.getRandomProxy(),
headers: sessionManager.getQmHeaders(),
successfulCalls: 0,
failedCalls: 0,
lastUsed: new Date()
};
// Get proxy from proxy service
const proxyString = handler.services.proxy.getProxy();
// const session = {
// proxy: proxyString || 'http://proxy:8080',
// headers: sessionManager.getQmHeaders(),
// successfulCalls: 0,
// failedCalls: 0,
// lastUsed: new Date()
// };
handler.services.logger.info(`Creating session for ${sessionType}`)
// Add session to manager
sessionManager.addSession(sessionType, session);
// sessionManager.addSession(sessionType, session);
return {
sessionId: sessionType,