Replies: 9 comments 4 replies
-
Jobs include a timestamp and a finishOn fields that can be used for computing durations: https://api.docs.bullmq.io/classes/Job.html |
Beta Was this translation helpful? Give feedback.
-
Thank you, could you also explain the meaning of parameters in that object?) Don't see any explanation in docs.
For example, I have
What does each of them mean? |
Beta Was this translation helpful? Give feedback.
-
I'll write how I see that, correct me if I misunderstand something. meta.count - count of all jobs per hour(referring to data - an array of counts of jobs per point (per minute) |
Beta Was this translation helpful? Give feedback.
-
Meta is actually data used internally, maybe we should not expose it to avoid confusion. |
Beta Was this translation helpful? Give feedback.
-
@manast How to use this method to get the most recent jobs for a minute? |
Beta Was this translation helpful? Give feedback.
-
Not sure what you mean with that. The method returns the completed/failed jobs with "descending" order by default: |
Beta Was this translation helpful? Give feedback.
-
@manast But the .getJobs method always returns static job data. As well as with "asc = true" parameter |
Beta Was this translation helpful? Give feedback.
-
@Xrazik1 did solve this? |
Beta Was this translation helpful? Give feedback.
-
export async function getJobsPerMinute(queue: Queue): Promise<number> {
// Fetch metrics for completed jobs
const metrics = await queue.getMetrics('completed');
// Check for insufficient data: prevTS might be zero or metrics might be empty
if (!metrics || metrics.meta.prevTS === 0) {
return 0;
}
// Calculate elapsed time in minutes using the difference between timestamps
const elapsedTimeInMinutes = (Date.now() - metrics.meta.prevTS) / (1000 * 60);
// Handle division by zero
if (metrics.meta.count === 0) {
return 0;
}
// Calculate and round the average jobs per minute
const avgJobsPerMinute = metrics.meta.count / elapsedTimeInMinutes;
const roundedAvg = Math.round(avgJobsPerMinute);
return roundedAvg;
} |
Beta Was this translation helpful? Give feedback.
-
Does this library have a built-in mechanism for retrieving information about jobs completion duration? I could not find any methods containing execution time info in
QueueGetters.ts
Beta Was this translation helpful? Give feedback.
All reactions