more lint fixes
This commit is contained in:
parent
cc014de397
commit
3e545cdaa9
8 changed files with 29 additions and 38 deletions
|
|
@ -1,6 +1,5 @@
|
|||
import { Queue, QueueEvents } from 'bullmq';
|
||||
// import { getLogger } from '@stock-bot/logger';
|
||||
import type { Job } from 'bullmq';
|
||||
|
||||
// const logger = getLogger('queue-metrics');
|
||||
|
||||
|
|
@ -41,6 +40,7 @@ export class QueueMetricsCollector {
|
|||
private processingTimes: number[] = [];
|
||||
private completedTimestamps: number[] = [];
|
||||
private failedTimestamps: number[] = [];
|
||||
private jobStartTimes = new Map<string, number>();
|
||||
private readonly maxSamples = 1000;
|
||||
private readonly metricsInterval = 60000; // 1 minute
|
||||
|
||||
|
|
@ -68,33 +68,20 @@ export class QueueMetricsCollector {
|
|||
});
|
||||
|
||||
// Track processing times
|
||||
this.queueEvents.on('active', async ({ jobId }) => {
|
||||
const job = await this.getJob(jobId);
|
||||
if (job) {
|
||||
(job as any)._startTime = Date.now();
|
||||
}
|
||||
this.queueEvents.on('active', ({ jobId }) => {
|
||||
this.jobStartTimes.set(jobId, Date.now());
|
||||
});
|
||||
|
||||
this.queueEvents.on('completed', async ({ jobId }) => {
|
||||
const job = await this.getJob(jobId);
|
||||
if (job && (job as any)._startTime) {
|
||||
const processingTime = Date.now() - (job as any)._startTime;
|
||||
this.queueEvents.on('completed', ({ jobId }) => {
|
||||
const startTime = this.jobStartTimes.get(jobId);
|
||||
if (startTime) {
|
||||
const processingTime = Date.now() - startTime;
|
||||
this.recordProcessingTime(processingTime);
|
||||
this.jobStartTimes.delete(jobId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get job by ID
|
||||
*/
|
||||
private async getJob(jobId: string): Promise<Job | undefined> {
|
||||
try {
|
||||
return await this.queue.getJob(jobId) || undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Record processing time
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue