-
Hi, we are looking at using pg-boss for a couple of use cases. One of the use cases would need something similar to singletonKey but instead of blocking the job insertion we would like to add the job but only allow one message to be consumed at a time for that key value. Does anyone have any thoughts on whether this could be achieved? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I'm assuming in your question that you want concurrency as high as possible, but only one worker per key. This can't be achieved in pg-boss in isolation (yet). One option I think could work that has a fairly low performance impact would be adding a new unique constraint ( |
Beta Was this translation helpful? Give feedback.
I'm assuming in your question that you want concurrency as high as possible, but only one worker per key. This can't be achieved in pg-boss in isolation (yet).
One option I think could work that has a fairly low performance impact would be adding a new unique constraint (
singletonKey WHERE state='active'
) and then add anON CONFLICT (singletonKey) DO NOTHING
in the fetch command's update to fail gracefully when attempting to put the second job into active state.