fixing batch before moving to the apps

This commit is contained in:
Boki 2025-06-19 21:33:31 -04:00
parent 8c2f98e010
commit 3534a2c47b
14 changed files with 43 additions and 884 deletions

View file

@ -2,7 +2,7 @@ import { Queue, QueueEvents } from 'bullmq';
import { getLogger } from '@stock-bot/logger';
import type { Job } from 'bullmq';
const logger = getLogger('queue-metrics');
// const logger = getLogger('queue-metrics');
export interface QueueMetrics {
// Job counts
@ -55,20 +55,20 @@ export class QueueMetricsCollector {
* Setup event listeners for metrics collection
*/
private setupEventListeners(): void {
this.queueEvents.on('completed', ({ jobId, returnvalue, prev }) => {
this.queueEvents.on('completed', () => {
// Record completion
this.completedTimestamps.push(Date.now());
this.cleanupOldTimestamps();
});
this.queueEvents.on('failed', ({ jobId, failedReason, prev }) => {
this.queueEvents.on('failed', () => {
// Record failure
this.failedTimestamps.push(Date.now());
this.cleanupOldTimestamps();
});
// Track processing times
this.queueEvents.on('active', async ({ jobId, prev }) => {
this.queueEvents.on('active', async ({ jobId }) => {
const job = await this.getJob(jobId);
if (job) {
(job as any)._startTime = Date.now();
@ -177,11 +177,11 @@ export class QueueMetricsCollector {
const sum = sorted.reduce((acc, val) => acc + val, 0);
return {
avg: Math.round(sum / sorted.length),
min: sorted[0],
max: sorted[sorted.length - 1],
p95: sorted[Math.floor(sorted.length * 0.95)],
p99: sorted[Math.floor(sorted.length * 0.99)],
avg: sorted.length > 0 ? Math.round(sum / sorted.length) : 0,
min: sorted[0] || 0,
max: sorted[sorted.length - 1] || 0,
p95: sorted[Math.floor(sorted.length * 0.95)] || 0,
p99: sorted[Math.floor(sorted.length * 0.99)] || 0,
};
}