Does trigger.dev support priority queue? #503
-
My use case is to have free users and paid users for AI image generation service and I want paid users to frontrun free users when they enqueue their jobs. I'm not super sure exactly about which data structure or algorithm I need but roughly I need to be able to rearrange the order of jobs based on user tier and their usage frequency somehow. Paid users will enjoy fast AI image generation and free users will not. Users on the same tier that use the service more often than others also should be deprioritized. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
In v3 we have more concurrency controls. You can define queues and attach them to Jobs (including sharing them across Jobs, which is what you need to do for your use case). Then when you trigger the Job you can specify a To be more concrete: const serialTenantQueue = queue({
name: "serial-tenant-queue",
concurrencyLimit: 1,
});
export const subscriptionCheck = task({
id: "subscription-check",
queue: serialTenantQueue,
run: async ({ payload }: { payload: number }) => {
return "something";
},
});
export const productData = task({
id: "product-data",
queue: serialTenantQueue,
run: async ({ payload }: { payload: number }) => {
return "something";
},
});
subscriptionCheck.trigger({
payload: 123,
options: {
//this effectively creates a serialTenantQueue for each unique concurrencyKey
concurrencyKey: "usr-12345",
},
});
//this won't run until the above task is finished because they share the same queue + concurrencyKey
productData.trigger({
payload: 123,
options: {
//this effectively creates a serialTenantQueue for each unique concurrencyKey
concurrencyKey: "usr-12345",
},
}); |
Beta Was this translation helpful? Give feedback.
In v3 we have more concurrency controls. You can define queues and attach them to Jobs (including sharing them across Jobs, which is what you need to do for your use case). Then when you trigger the Job you can specify a
concurrencyKey
– that will effectively create a copy of that queue with that key.To be more concrete: