Queues archiving via edge function
I'm working on implementing Queues (pgmq) like suggested in the tutorial. I have RLS and Expose Queues via PostgREST enabled but i'm only accessing them directly with edge functions. I can't seem to get the edge function to archive it. Are there any edge function examples out there that share the code? I don't see the edge fucntion code in the example https://youtu.be/UEwfaElBnZk . Everything appears to be working other than the deno code to move it to the archive a_queue_name. As in my function is adding, processing, and removing them from the queue... just not the history.
Supabase
YouTube
We added the missing piece! š§©
Supabase Queues allow you to store a sequence of messages allowing for batch processing, or long running asynchronous tasks. In this video, Jon Meyers demonstrates how to add and remove messages in the Queue from a Supabase Edge Function, and how to retry a message if it fails to be processed.
āļø Supabase Queues (blog): https://supabase.com/blo...
4 Replies
I don't know of official samples with these implementations, however I can share how I have implemented on a project of my own...
First I like to create a client for queues:
and later on the functions I imported it and use it like this:
And I call the edge function every X time with a cron.
Thank you for taking the time to share your code - it's very similar to what I'm doing. Does this move the message to the archive queue?
My pops and deletes work, but I'm not seeing the archive. Maybe my assumption is flawed, but I think I should be able to go to my
I've tried many different forms of the following and keep getting similar errors:
My pops and deletes work, but I'm not seeing the archive. Maybe my assumption is flawed, but I think I should be able to go to my
pgmq
schema and see both tables q_queuename
and a_queuename
tables. I do see them and can see the messages queued up in the q_
table but never see them in the a_
table.I've tried many different forms of the following and keep getting similar errors:
Attempting to archive message:
Archive operation completed:
{
success: false,
message_id: 120,
queue: "queuename"
}
{
queue_name: "queuename",
message_id: 120,
msg_details: {
read_ct: 0,
enqueued_at: "2025-01-27T18:47:12.449099+00:00",
vt: "2025-01-27T18:47:12.450303+00:00"
}
}
And here's the code I'm using for the archive operation:
const { data: archiveData, error: archiveError } = await queues.rpc('archive', {
queue_name: 'notification_queue',
message_id: messageId
});
It seems with pgmq you need to have partitioning enabled to use the archive feature. I see Partitioned Queues are listed as 'coming soon' in the UI when you create the queue. I think that explains it.Any error in the postgres logs? If you attempt to archive from the SQL console, by running
does that work?
That works... interesting. š