Feature request: Task priority
pavdwest opened this issue · 1 comments
First off, thank you very much for this very useful framework.
I do apologise in advance if this isn't the correct place to raise a feature request or if you're not looking at requests at all. In any case some basic task prioritisation would be very useful. The ideal implementation would allow multiple worker nodes (a single resource pool) to pick up tasks from a single task queue that handles the prioritisation internally, abstracted away from the consumer.
To illustrate:
from saq import Queue
# Create queue
queue = Queue.from_url("redis://localhost")
# Enqueue tasks (We assume a higher number is a higher priority)
low_priority_task = await queue.enqueue("some_task", a=5, priority=25)
high_priority_task =await queue.enqueue("some_task", a=5, priority=100)
medium_priority_task = await queue.enqueue("some_task", a=5, priority=50)
Now when starting up a worker once these jobs have been enqueued successfully, these jobs will be popped in the order:
- high_priority_task
- medium_priority_task
- low_priority_task
P.S. Queue-based priorities can be nice but often have significant infrastructure/configuration trade-offs so I much prefer Enqueue-time prioritisation.
there are no plans to implement priorities since you can just have different queue based priorities.
that said if you made a simple pr to do this i would accept it