Queues: add a pgmq_public.set_vt wrapper so Data API consumers can extend or delay a message #54363
Unanswered
martijn00
asked this question in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
The
pgmq_publicwrappers that Studio installs when Queues are exposed through the Data API (getExposeQueuesSQLinpackages/pg-meta/src/sql/studio/database/queues.ts) coversend,send_batch,read,pop,archiveanddelete. There is no wrapper forpgmq.set_vt, so a consumer that reads through PostgREST orsupabase.schema('pgmq_public').rpc(...)cannot change a message's visibility timeout after it has read it.That rules out two common worker patterns:
sleep_seconds := 30, and the job takes longer. Withoutset_vtit cannot extend its lease, so the message becomes visible again and a second worker picks it up while the first is still running. The only choice is a long timeout up front, which delays the retry when a worker really dies.set_vt(queue, msg_id, delay)to retry after 30 s, then 2 min, and so on. Without it, the message reappears when the original timeout runs out, so every retry runs at the same interval.We maintain an open source job queue on top of pgmq. Over a direct Postgres connection it uses
pgmq.set_vtfor both. Over the Data API with onlypgmq_public, we have to document that heartbeats and backoff do nothing (limitations.mdx), or ask users to install their own wrappers in another exposed schema.Proposal
Add one wrapper next to the others, with the same grants and
search_path:It should also be added to
HIDE_QUEUES_FROM_POSTGREST_SQLso disabling exposure drops it, and the Queues API docs would list it with the others. Since the wrappers run as the caller,set_vtwould need the same update privilege and RLS policy on the queue table thatreadalready needs, because both update the message row.All reactions