Closed rkperes closed 2 months ago
@rkperes I was facing the same since I am using pg-boss in my tests too so I need to create queues and then purge them and eventually delete them. I'm fine with purge instead of deleting but for creation I worked around the issue with duplicate keys by doing the following
const currentQueue = await boss.getQueue(queueName)
if(!currentQueue){
await boss.createQueue(queueName);
}
I did the same thing in the pg-boss test suite as well
Ran into the same issue. While it's easy to fix, it feels wrong to have to use it, unless I misunderstanding how to structure pg-boss
apps.
IIUC you declare the queues (createQueue
) and their handlers (boss.work
) at runtime. If your worker restarts, on a new deploy for eg, createQueue
should be a no-op.
I was on the fence about failing an existing queue, but you guys won me over. :)
I've just started using pg-boss, so pardon if I'm missing something basic. I started already with the latest version v10.0.1. Since v10.0.0, we need to call
createQueue
before creating any jobs (even workers, AFAIU). I'm starting my workers from Next.jsinstrumentation.ts
, as also seen in https://github.com/mjftw/next-boss-example. While that works, I'm always getting logs for the duplicate constraint violation errors (after a first server start, where the create generates the first entries):~Additionally, I couldn't catch the error to handle it and call an update instead.~ (Edit: I wasn't properly handling the promise. Nonetheless, it'd be nice to be able to easily handle the upserts suggested below.)
Is there a general guideline on how to approach the
createQueue
calls? Or could we consider anupsert
API that'd guarantee the queue is either created or updated with the given policies?