-
Notifications
You must be signed in to change notification settings - Fork 625
UN-3501 [FEAT] Plumb fairness key on every dispatch() call site #2003
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
Merged
+407
−75
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
30976d5
UN-3501 [FEAT] Plumb fairness key on every dispatch() call site
muhammad-ali-e 6581184
UN-3501 [FIX] Carry fairness key in Celery message headers, not kwargs
muhammad-ali-e e9a9d52
Merge branch 'main' into UN-3501-fairness-key
muhammad-ali-e 93e8a38
UN-3501 [FIX] Address PR review feedback on fairness key
muhammad-ali-e 3796c54
UN-3501 [FIX] Lower cognitive complexity in fairness canary tests
muhammad-ali-e 24f8adf
Merge branch 'main' into UN-3501-fairness-key
muhammad-ali-e 97c6623
UN-3501 [FIX] Address Greptile + CodeRabbit findings on fairness key
muhammad-ali-e 3aea5b5
Merge branch 'main' into UN-3501-fairness-key
muhammad-ali-e f440e4e
UN-3501 [DOCS] Trim plan-stage references and verbose history from fa…
muhammad-ali-e 6f8ed66
UN-3501 [FIX] Replace invented tier vocabulary with labs-grounded wor…
muhammad-ali-e 02b6a4b
UN-3501 [REFACTOR] WorkloadType -> StrEnum; scope fairness to workflo…
muhammad-ali-e f914c9a
UN-3501 [FIX] Canary error message pointed at deleted FairnessKey.sys…
muhammad-ali-e 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,11 @@ | ||
| """Queue-backend seam for workers. | ||
| """Queue-backend seam. | ||
| This module is the single place where the choice of queue substrate | ||
| (Celery+RabbitMQ today; PG Queue in the future) lives. | ||
| Today both entry points are no-op aliases over Celery primitives: | ||
| * ``dispatch(task_name, args, kwargs, queue)`` -> ``current_app.send_task(...)`` | ||
| * ``@worker_task`` -> ``@shared_task`` | ||
| A later phase will route specific tasks through a non-Celery substrate | ||
| (PG Queue) based on configuration; until then everything goes to Celery. | ||
| The exact routing mechanism is intentionally not pinned here. | ||
| Call sites should migrate to this module so the eventual substrate switch | ||
| is a single-flag operation rather than a codebase-wide rewrite. | ||
| Single place where the substrate choice (Celery today; PG Queue later) | ||
| lives. Both entry points are transparent passthroughs to Celery today. | ||
| """ | ||
|
|
||
| from .decorator import worker_task | ||
| from .dispatch import dispatch | ||
| from .fairness import FairnessKey | ||
|
|
||
| __all__ = ["dispatch", "worker_task"] | ||
| __all__ = ["FairnessKey", "dispatch", "worker_task"] |
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
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 |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| """Workflow-execution fairness key. | ||
| Attached to dispatches that start a workflow execution. Non-workflow | ||
| worker tasks (notifications, callbacks, healthchecks) pass | ||
| ``fairness=None``. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| from enum import StrEnum | ||
| from typing import Final | ||
|
|
||
|
|
||
| class WorkloadType(StrEnum): | ||
| """Workflow execution type. Labs L2 check is binary api-vs-not.""" | ||
|
|
||
| API = "api" | ||
| NON_API = "non_api" | ||
|
|
||
|
|
||
| # pipeline_priority bounds per labs schema (1..10, higher = sooner). | ||
| MIN_PRIORITY: Final[int] = 1 | ||
| MAX_PRIORITY: Final[int] = 10 | ||
| DEFAULT_PRIORITY: Final[int] = 5 | ||
|
|
||
| # Header (not kwarg) so task-body signatures without **kwargs aren't broken. | ||
| FAIRNESS_HEADER_NAME: Final[str] = "x-fairness-key" | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class FairnessKey: | ||
| """Routing metadata for a workflow-execution dispatch. | ||
| ``org_id=None`` is valid for cross-org tasks — the scheduler's | ||
| ``org_config`` JOIN simply doesn't match. | ||
| """ | ||
|
|
||
| org_id: str | None | ||
| workload_type: WorkloadType | ||
| pipeline_priority: int = DEFAULT_PRIORITY | ||
|
|
||
| def __post_init__(self) -> None: | ||
| if not MIN_PRIORITY <= self.pipeline_priority <= MAX_PRIORITY: | ||
| raise ValueError( | ||
| "pipeline_priority out of range " | ||
| f"[{MIN_PRIORITY}, {MAX_PRIORITY}]: {self.pipeline_priority}" | ||
| ) | ||
|
|
||
| def to_dict(self) -> dict[str, str | int | None]: | ||
| return { | ||
| "org_id": self.org_id, | ||
| "workload_type": self.workload_type.value, | ||
| "pipeline_priority": self.pipeline_priority, | ||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.