work on qm
This commit is contained in:
parent
ca1f658be6
commit
3fb9df425c
5 changed files with 93 additions and 113 deletions
|
|
@ -2,14 +2,14 @@
|
|||
* QM Session Actions - Session management and creation
|
||||
*/
|
||||
|
||||
import type { IServiceContainer } from '@stock-bot/handlers';
|
||||
import { BaseHandler } from '@stock-bot/core/handlers';
|
||||
import { QM_SESSION_IDS, SESSION_CONFIG } from '../shared/config';
|
||||
import { QMSessionManager } from '../shared/session-manager';
|
||||
|
||||
/**
|
||||
* Check existing sessions and queue creation jobs for needed sessions
|
||||
*/
|
||||
export async function checkSessions(services: IServiceContainer): Promise<{
|
||||
export async function checkSessions(handler: BaseHandler): Promise<{
|
||||
cleaned: number;
|
||||
queued: number;
|
||||
message: string;
|
||||
|
|
@ -19,12 +19,13 @@ export async function checkSessions(services: IServiceContainer): Promise<{
|
|||
// Check which session IDs need more sessions and queue creation jobs
|
||||
let queuedCount = 0;
|
||||
for (const sessionId of Object.values(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 services.queue.getQueue('qm').add('create-session', { sessionId });
|
||||
services.logger.log(`Queued job to create session for ${sessionId}`);
|
||||
await handler.scheduleOperation('create-session', { sessionId });
|
||||
handler.services.logger.log(`Queued job to create session for ${sessionId}`);
|
||||
queuedCount++;
|
||||
}
|
||||
}
|
||||
|
|
@ -41,29 +42,17 @@ export async function checkSessions(services: IServiceContainer): Promise<{
|
|||
* Create a single session for a specific session ID
|
||||
*/
|
||||
export async function createSingleSession(
|
||||
services: IServiceContainer,
|
||||
handler: BaseHandler,
|
||||
input: any
|
||||
): Promise<{ sessionId: string; status: string; sessionType: string }> {
|
||||
|
||||
const { sessionId: sessionType = 'default' } = input || {};
|
||||
const sessionManager = QMSessionManager.getInstance();
|
||||
|
||||
// Check if we're at capacity for this session type
|
||||
if (sessionManager.isAtCapacity(sessionType)) {
|
||||
return {
|
||||
sessionId: '',
|
||||
status: 'skipped',
|
||||
sessionType,
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: Get actual proxy and headers from proxy service
|
||||
const session = {
|
||||
proxy: 'http://proxy:8080', // Placeholder
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (compatible; QMBot/1.0)',
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
// proxy: handler.services.getRandomProxy(),
|
||||
headers: sessionManager.getQmHeaders(),
|
||||
successfulCalls: 0,
|
||||
failedCalls: 0,
|
||||
lastUsed: new Date()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue