tembo-io / pgmq

A lightweight message queue. Like AWS SQS and RSMQ but on Postgres.
PostgreSQL License
2.68k stars 71 forks source link

pgmq.metrics for readily available messages #301

Closed CGenie closed 2 weeks ago

CGenie commented 2 months ago

The pgmq.metrics function returns, in particular, the queue_length column (https://tembo-io.github.io/pgmq/api/sql/functions/#metrics) which is the total number of messages.

However, when all my messages have vt set sometime in the future, even though queue_length > 0 I might not get any message when I issue pgmq.read (c.f. https://tembo-io.github.io/pgmq/api/sql/functions/#set_vt). My suggestion is to also add something like queue_available_length which returns the number of messages that are readily available.

ChuckHend commented 2 months ago

This is a good idea and I think the implementation would be fairly straight forward.

We'd need to add the queue_availalbe_length or queue_length_visible to pgmq.metrics_result type.

Then add something like count(*) where vt <= now() someplace in pgmq.metrics()

v0idpwn commented 2 weeks ago

Done in #332, will be released in 1.5.0. Thank you for creating the issue