Merge pull request #3743 from omnivore-app/feat/jobs-queue-age

Export the age of the oldest job in the queue
This commit is contained in:
Jackson Harper 2024-03-28 11:57:19 +08:00 committed by GitHub
commit 1f9b7138d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -215,7 +215,6 @@ const main = async () => {
let output = ''
const metrics: JobType[] = ['active', 'failed', 'completed', 'prioritized']
const counts = await queue.getJobCounts(...metrics)
console.log('counts: ', counts)
metrics.forEach((metric, idx) => {
output += `# TYPE omnivore_queue_messages_${metric} gauge\n`
@ -242,6 +241,18 @@ const main = async () => {
}
}
// Export the age of the oldest prioritized job in the queue
const oldestJobs = await queue.getJobs(['prioritized'], 0, 1, true)
if (oldestJobs.length > 0) {
const currentTime = Date.now()
const ageInSeconds = (currentTime - oldestJobs[0].timestamp) / 1000
output += `# TYPE omnivore_queue_messages_oldest_job_age_seconds gauge\n`
output += `omnivore_queue_messages_oldest_job_age_seconds{queue="${QUEUE_NAME}"} ${ageInSeconds}\n`
} else {
output += `# TYPE omnivore_queue_messages_oldest_job_age_seconds gauge\n`
output += `omnivore_queue_messages_oldest_job_age_seconds{queue="${QUEUE_NAME}"} ${0}\n`
}
res.status(200).setHeader('Content-Type', 'text/plain').send(output)
})