import { getChannel } from "@/lib/lavinmq"; export const QUEUE_NAME = "publish_jobs"; export async function enqueuePublishJob(postId: string) { const channel = await getChannel(); // assertQueue checks if the queue exists, if not it creates it. // durable: true means the queue survives broker restarts await channel.assertQueue(QUEUE_NAME, { durable: true }); const message = JSON.stringify({ postId }); // persistent: true means messages are saved to disk const sent = channel.sendToQueue(QUEUE_NAME, Buffer.from(message), { persistent: true }); if (sent) { console.log(`[LavinMQ] Enqueued job for post ${postId}`); } else { console.error(`[LavinMQ] Failed to enqueue job for post ${postId}`); throw new Error("Failed to enqueue job"); } }