-
Notifications
You must be signed in to change notification settings - Fork 461
feat: add a separate high_priority queue #7154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
psincraian
wants to merge
7
commits into
main
Choose a base branch
from
PUB-567
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+95
−3
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8e0f480
feat: add a separate high_priority queue
psincraian a3a414c
fix: lint
psincraian be77eeb
refactor: use a constant for the TaskQueue
psincraian 5d8b8ef
refactor: infer the queue name from task priority
psincraian b75f91e
refator: revert task files to be the same as main
psincraian 45bae6e
fix: make worker listen to both queues on local
psincraian 6e2a6df
fix: scheduler running on default queue only
psincraian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,17 +178,29 @@ class TaskPriority(IntEnum): | |
LOW = 100 | ||
|
||
|
||
class TaskQueue: | ||
HIGH_PRIORITY = "high_priority" | ||
DEFAULT = "default" | ||
|
||
|
||
P = ParamSpec("P") | ||
|
||
|
||
def actor[**P, R]( | ||
actor_class: Callable[..., dramatiq.Actor[Any, Any]] = dramatiq.Actor, | ||
actor_name: str | None = None, | ||
queue_name: str = "default", | ||
queue_name: str | None = None, | ||
priority: TaskPriority = TaskPriority.LOW, | ||
broker: dramatiq.Broker | None = None, | ||
**options: Any, | ||
) -> Callable[[Callable[P, Awaitable[R]]], Callable[P, Awaitable[R]]]: | ||
if queue_name is None: | ||
queue_name = ( | ||
TaskQueue.HIGH_PRIORITY | ||
if priority == TaskPriority.HIGH | ||
else TaskQueue.DEFAULT | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clever! I like the idea that it's made transparently :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hate duplicated code :D |
||
|
||
def decorator( | ||
fn: Callable[P, Awaitable[R]], | ||
) -> Callable[P, Awaitable[R]]: | ||
|
@@ -225,4 +237,6 @@ async def _wrapped_fn(*args: P.args, **kwargs: P.kwargs) -> R: | |
"enqueue_events", | ||
"get_retries", | ||
"can_retry", | ||
"TaskPriority", | ||
"TaskQueue", | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't start the scheduler on both workers, otherwise we'll get duplicated jobs 🙂
Next stop would be to have a dedicated server just for the scheduler, so we can independently scale the worker horizontally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha! Good catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scheduler is considered a high or normal/medium priority? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pushed to default queue for now