fixed up worker counts

This commit is contained in:
Boki 2025-06-24 15:09:50 -04:00
parent f41622e530
commit fa67d666dc
5 changed files with 182 additions and 28 deletions

View file

@ -100,6 +100,16 @@ export class MonitoringService {
symbols: 'data-pipeline',
};
// Worker configuration per queue (from service configs)
const workerConfig: Record<string, { count: number; concurrency: number }> = {
qm: { count: 1, concurrency: 2 },
ib: { count: 1, concurrency: 1 },
ceo: { count: 1, concurrency: 2 },
webshare: { count: 1, concurrency: 1 },
exchanges: { count: 1, concurrency: 1 },
symbols: { count: 1, concurrency: 2 },
};
const queueNames = Object.keys(handlerMapping);
this.logger.debug('Using known queue names', { count: queueNames.length, names: queueNames });
@ -124,6 +134,10 @@ export class MonitoringService {
// Get stats directly from BullMQ
const queueStats = await this.getQueueStatsForBullQueue(bullQueue, handlerName);
// Get actual worker count from BullMQ
const actualWorkerCount = await this.getActiveWorkerCountFromBullMQ(bullQueue);
const configuredWorkers = workerConfig[handlerName] || { count: 0, concurrency: 1 };
stats.push({
name: handlerName,
service: serviceName,
@ -131,8 +145,8 @@ export class MonitoringService {
connected: true,
jobs: queueStats,
workers: {
count: 0,
concurrency: 1,
count: actualWorkerCount,
concurrency: configuredWorkers.concurrency,
},
});
@ -790,4 +804,30 @@ export class MonitoringService {
percentage: (usedMem / totalMem) * 100,
};
}
/**
* Get active worker count from Redis
*/
/**
* Get active worker count using BullMQ's built-in tracking
*/
private async getActiveWorkerCountFromBullMQ(bullQueue: any): Promise<number> {
try {
// Use BullMQ's built-in getWorkers method
if (bullQueue.getWorkers && typeof bullQueue.getWorkers === 'function') {
const workers = await bullQueue.getWorkers();
return workers.length;
}
// Fallback to getWorkersCount if available
if (bullQueue.getWorkersCount && typeof bullQueue.getWorkersCount === 'function') {
return await bullQueue.getWorkersCount();
}
return 0;
} catch (error) {
this.logger.debug('Failed to get active worker count from BullMQ', { error });
return 0;
}
}
}