Dynamic worker by queueName #35
-
Hi! there is any way to create dynamically a worker queue? The need is to have different queues such as embeddings-tasks-acme1, embeddings-tasks-acme2, etc for concurrency EdgeWorker.start(handler, {
queueName: "embeddings-tasks", // <-- here
maxConcurrent: 5,
maxPollSeconds: 5,
pollIntervalMs: 200,
// how long to wait before retrying a failed job
retryDelay: 60,
retryLimit: 5,
}); one option can be to transform queueName to be string | (req) => string | async (req) => string @jumski how much can be difficult to implement? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey again, @piccinnigius! Short answer: it is hard to implement due to limitations of Edge Runtime (see Starting Workers below) Can you give more details on your use case? Do you need more queues to do a fair-processing, so one tenant does not block the queue for other tenants? In the mean time I want to acknowledge few things. Worker-Queue relationship
😞 The one queue per worker is hard to changeThis was a deliberate decision when planning the architecture of the worker:
Starting WorkersCurrently starting a worker requires firing an HTTP request, but you are not guaranteed to start new worker every time you call it via HTTP - this is decided by the Supabase API Gateway (kong/kong). It is a reverse proxy with built in load balancer and it spawns new Edge Function instances depending on the load (to increase HTTP throughput) or if there is no instance at all for given edge function. Given worker only needs a single http request per instance it is not possible to reliably start new "instances" by firing http requests against given Edge Function. Dynamic queues won't work in this setupYour suggestion to create a queue based on the HTTP request payload would not really work with this system, because you cannot guarantee the request will spawn a new worker (Kong decides when to do that). 💡 WorkaroundsCreating more workers for the same queueThe simplest thing you can try is to deploy more functions with workers, all processing the same queue using same handler. Implementing less-unfair processing with multiple queuesGiven the limitation of worker processing only a single queue |
Beta Was this translation helpful? Give feedback.
I have few ideas how to solve it, but it is really very use-case specific.
Can you share more details?
Workarounds to consider (we can discuss further)
Tenant per queue
Easiest option but limited to 50 tenants on free tier - just assign a new queue every time you get a new tenant.
You can deploy the queues and workers upfront and just assign them to new tenants as they arrive.
If you run out of queues, you can start assigning…