-
Notifications
You must be signed in to change notification settings - Fork 336
Add concurrency policy #3267
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
machichima
merged 8 commits into
flyteorg:master
from
thomasjhuang:thomasjhuang/concurrency
Oct 3, 2025
Merged
Add concurrency policy #3267
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
57c6853
Add concurrency policy
thomasjhuang b2c1b4f
Update to latest idl
thomasjhuang e99cf57
Reformat with ruff
thomasjhuang bf2e179
Change reference
thomasjhuang aef83a8
Update test
thomasjhuang e1ba971
Update tests/flytekit/unit/models/test_concurrency.py
thomasjhuang 694ad1b
Update comment
thomasjhuang d618d21
Fix lint
thomasjhuang 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
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,62 @@ | ||
| from flyteidl.admin import launch_plan_pb2 as _launch_plan_idl | ||
|
|
||
| from flytekit.models import common as _common | ||
|
|
||
|
|
||
| class ConcurrencyLimitBehavior(object): | ||
| SKIP = _launch_plan_idl.CONCURRENCY_LIMIT_BEHAVIOR_SKIP | ||
|
|
||
| @classmethod | ||
| def enum_to_string(cls, val): | ||
| """ | ||
| :param int val: | ||
| :rtype: Text | ||
| """ | ||
| if val == cls.SKIP: | ||
| return "SKIP" | ||
| else: | ||
| return "<UNKNOWN>" | ||
|
|
||
|
|
||
| class ConcurrencyPolicy(_common.FlyteIdlEntity): | ||
| """ | ||
| Defines the concurrency policy for a launch plan. | ||
| """ | ||
|
|
||
| def __init__(self, max_concurrency: int, behavior: ConcurrencyLimitBehavior = None): | ||
| self._max_concurrency = max_concurrency | ||
| self._behavior = behavior if behavior is not None else ConcurrencyLimitBehavior.SKIP | ||
|
|
||
| @property | ||
| def max_concurrency(self) -> int: | ||
| """ | ||
| Maximum number of concurrent workflows allowed. | ||
| """ | ||
| return self._max_concurrency | ||
|
|
||
| @property | ||
| def behavior(self) -> ConcurrencyLimitBehavior: | ||
| """ | ||
| Policy behavior when concurrency limit is reached. | ||
| """ | ||
| return self._behavior | ||
|
|
||
| def to_flyte_idl(self) -> _launch_plan_idl.ConcurrencyPolicy: | ||
| """ | ||
| :rtype: flyteidl.admin.launch_plan_pb2.ConcurrencyPolicy | ||
| """ | ||
| return _launch_plan_idl.ConcurrencyPolicy( | ||
| max=self.max_concurrency, | ||
| behavior=self.behavior, | ||
| ) | ||
|
|
||
| @classmethod | ||
| def from_flyte_idl(cls, pb2_object: _launch_plan_idl.ConcurrencyPolicy) -> "ConcurrencyPolicy": | ||
| """ | ||
| :param flyteidl.admin.launch_plan_pb2.ConcurrencyPolicy pb2_object: | ||
| :rtype: ConcurrencyPolicy | ||
| """ | ||
| return cls( | ||
| max_concurrency=pb2_object.max, | ||
| behavior=pb2_object.behavior, | ||
| ) | ||
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
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,41 @@ | ||
| from flyteidl.admin import launch_plan_pb2 as _launch_plan_idl | ||
|
|
||
| from flytekit.models.concurrency import ConcurrencyLimitBehavior, ConcurrencyPolicy | ||
|
|
||
|
|
||
| def test_concurrency_limit_behavior(): | ||
| assert ConcurrencyLimitBehavior.SKIP == _launch_plan_idl.CONCURRENCY_LIMIT_BEHAVIOR_SKIP | ||
|
|
||
| # Test enum to string conversion | ||
| assert ConcurrencyLimitBehavior.enum_to_string(ConcurrencyLimitBehavior.SKIP) == "SKIP" | ||
| assert ConcurrencyLimitBehavior.enum_to_string(999) == "<UNKNOWN>" | ||
|
|
||
|
|
||
| def test_concurrency_policy_serialization(): | ||
| policy = ConcurrencyPolicy(max_concurrency=1, behavior=ConcurrencyLimitBehavior.SKIP) | ||
|
|
||
| assert policy.max_concurrency == 1 | ||
| assert policy.behavior == ConcurrencyLimitBehavior.SKIP | ||
|
|
||
| # Test serialization to protobuf | ||
| pb = policy.to_flyte_idl() | ||
| assert isinstance(pb, _launch_plan_idl.ConcurrencyPolicy) | ||
| assert pb.max == 1 | ||
| assert pb.behavior == _launch_plan_idl.CONCURRENCY_LIMIT_BEHAVIOR_SKIP | ||
|
|
||
| # Test deserialization from protobuf | ||
| policy2 = ConcurrencyPolicy.from_flyte_idl(pb) | ||
| assert policy2.max_concurrency == 1 | ||
| assert policy2.behavior == ConcurrencyLimitBehavior.SKIP | ||
|
|
||
|
|
||
| def test_concurrency_policy_with_different_max(): | ||
| # Test with a higher max value | ||
| policy = ConcurrencyPolicy(max_concurrency=5, behavior=ConcurrencyLimitBehavior.SKIP) | ||
| assert policy.max_concurrency == 5 | ||
|
|
||
| pb = policy.to_flyte_idl() | ||
| assert pb.max == 5 | ||
|
|
||
| policy2 = ConcurrencyPolicy.from_flyte_idl(pb) | ||
| assert policy2.max_concurrency == 5 |
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.