timgit / pg-boss

Queueing jobs in Postgres from Node.js like a boss
MIT License
2.02k stars 157 forks source link

Peeking a job queue? #269

Open noamgat opened 3 years ago

noamgat commented 3 years ago

Hi, I'm using PGBoss in a setup that uses external job fulfillers, so I expose a REST API that includes things like getNextJob(queueName) and complete(jobId). I want to be able to build a monitoring solution on top of this. The monitor should be able to know that no worker has taken a job from a queue, by finding out that the next pending job on the AAA queue was created more than an hour ago. boss.getQueueSize() gives us the number of projects in the queue, but not how long ago it was created. fetch() gives me the job information, but also acts as a worker and removes the job from a pending state.

Is there a "peek" option (very common in queues) that allows me to get the information of the next job in a queue, without dequeuing it?

timgit commented 3 years ago

There's not a peek() api in pg-boss, so you will need to build this yourself until it exists. Since pg-boss is also a priority queue, the fetch order isn't always creation date if you opt into creating higher priority jobs that can jump to the front of the queue. Keep that in mind if you decide to set this up via a custom SQL solution in the interim of this feature existing.