-
Notifications
You must be signed in to change notification settings - Fork 42
Introduce new models for graph execution and added Start_delay #348
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c4da69c
Update version to 0.0.2b5 and introduce new models for graph execution
NiveditJain 3934cfd
Refactor __init__.py to streamline exports and include new models
NiveditJain a3d1a5a
Refactor tests to remove TriggerState and utilize GraphNodeModel
NiveditJain 4b9fbbf
Add class method decorators to StoreConfigModel validators
NiveditJain 7ca6347
Remove unused import of asyncio in test_models_and_statemanager_new.p…
NiveditJain 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| version = "0.0.2b4" | ||
| version = "0.0.2b5" |
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,160 @@ | ||
| from pydantic import BaseModel, Field, field_validator | ||
| from typing import Any, Optional, List | ||
| from enum import Enum | ||
|
|
||
|
|
||
| class UnitesStrategyEnum(str, Enum): | ||
| ALL_SUCCESS = "ALL_SUCCESS" | ||
| ALL_DONE = "ALL_DONE" | ||
|
|
||
|
|
||
| class UnitesModel(BaseModel): | ||
| identifier: str = Field(..., description="Identifier of the node") | ||
| strategy: UnitesStrategyEnum = Field(default=UnitesStrategyEnum.ALL_SUCCESS, description="Strategy of the unites") | ||
|
|
||
|
|
||
| class GraphNodeModel(BaseModel): | ||
| node_name: str = Field(..., description="Name of the node") | ||
| namespace: str = Field(..., description="Namespace of the node") | ||
| identifier: str = Field(..., description="Identifier of the node") | ||
| inputs: dict[str, Any] = Field(..., description="Inputs of the node") | ||
| next_nodes: Optional[List[str]] = Field(None, description="Next nodes to execute") | ||
| unites: Optional[UnitesModel] = Field(None, description="Unites of the node") | ||
|
|
||
| @field_validator('node_name') | ||
| @classmethod | ||
| def validate_node_name(cls, v: str) -> str: | ||
| trimmed_v = v.strip() | ||
| if trimmed_v == "" or trimmed_v is None: | ||
| raise ValueError("Node name cannot be empty") | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return trimmed_v | ||
|
|
||
| @field_validator('identifier') | ||
| @classmethod | ||
| def validate_identifier(cls, v: str) -> str: | ||
| trimmed_v = v.strip() | ||
| if trimmed_v == "" or trimmed_v is None: | ||
| raise ValueError("Node identifier cannot be empty") | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| elif trimmed_v == "store": | ||
| raise ValueError("Node identifier cannot be reserved word 'store'") | ||
| return trimmed_v | ||
|
|
||
| @field_validator('next_nodes') | ||
| @classmethod | ||
| def validate_next_nodes(cls, v: Optional[List[str]]) -> Optional[List[str]]: | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| identifiers = set() | ||
| errors = [] | ||
| trimmed_v = [] | ||
|
|
||
| if v is not None: | ||
| for next_node_identifier in v: | ||
| trimmed_next_node_identifier = next_node_identifier.strip() | ||
|
|
||
| if trimmed_next_node_identifier == "" or trimmed_next_node_identifier is None: | ||
| errors.append("Next node identifier cannot be empty") | ||
| continue | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if trimmed_next_node_identifier in identifiers: | ||
| errors.append(f"Next node identifier {trimmed_next_node_identifier} is not unique") | ||
| continue | ||
|
|
||
| identifiers.add(trimmed_next_node_identifier) | ||
| trimmed_v.append(trimmed_next_node_identifier) | ||
| if errors: | ||
| raise ValueError("\n".join(errors)) | ||
| return trimmed_v | ||
|
|
||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @field_validator('unites') | ||
| @classmethod | ||
| def validate_unites(cls, v: Optional[UnitesModel]) -> Optional[UnitesModel]: | ||
| trimmed_v = v | ||
| if v is not None: | ||
| trimmed_v = UnitesModel(identifier=v.identifier.strip(), strategy=v.strategy) | ||
| if trimmed_v.identifier == "" or trimmed_v.identifier is None: | ||
| raise ValueError("Unites identifier cannot be empty") | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return trimmed_v | ||
|
|
||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| class RetryStrategyEnum(str, Enum): | ||
| EXPONENTIAL = "EXPONENTIAL" | ||
| EXPONENTIAL_FULL_JITTER = "EXPONENTIAL_FULL_JITTER" | ||
| EXPONENTIAL_EQUAL_JITTER = "EXPONENTIAL_EQUAL_JITTER" | ||
|
|
||
| LINEAR = "LINEAR" | ||
| LINEAR_FULL_JITTER = "LINEAR_FULL_JITTER" | ||
| LINEAR_EQUAL_JITTER = "LINEAR_EQUAL_JITTER" | ||
|
|
||
| FIXED = "FIXED" | ||
| FIXED_FULL_JITTER = "FIXED_FULL_JITTER" | ||
| FIXED_EQUAL_JITTER = "FIXED_EQUAL_JITTER" | ||
|
|
||
|
|
||
| class RetryPolicyModel(BaseModel): | ||
| max_retries: int = Field(default=3, description="The maximum number of retries", ge=0) | ||
| strategy: RetryStrategyEnum = Field(default=RetryStrategyEnum.EXPONENTIAL, description="The method of retry") | ||
| backoff_factor: int = Field(default=2000, description="The backoff factor in milliseconds (default: 2000 = 2 seconds)", gt=0) | ||
| exponent: int = Field(default=2, description="The exponent for the exponential retry strategy", gt=0) | ||
| max_delay: int | None = Field(default=None, description="The maximum delay in milliseconds (no default limit when None)", gt=0) | ||
|
|
||
|
|
||
| class StoreConfigModel(BaseModel): | ||
| required_keys: list[str] = Field(default_factory=list, description="Required keys of the store") | ||
| default_values: dict[str, str] = Field(default_factory=dict, description="Default values of the store") | ||
|
|
||
| @field_validator("required_keys") | ||
| @classmethod | ||
| def validate_required_keys(cls, v: list[str]) -> list[str]: | ||
| errors = [] | ||
| keys = set() | ||
| trimmed_keys = [] | ||
|
|
||
| for key in v: | ||
| trimmed_key = key.strip() if key is not None else "" | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if trimmed_key == "": | ||
| errors.append("Key cannot be empty or contain only whitespace") | ||
| continue | ||
|
|
||
| if '.' in trimmed_key: | ||
| errors.append(f"Key '{trimmed_key}' cannot contain '.' character") | ||
| continue | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if trimmed_key in keys: | ||
| errors.append(f"Key '{trimmed_key}' is duplicated") | ||
| continue | ||
|
|
||
| keys.add(trimmed_key) | ||
| trimmed_keys.append(trimmed_key) | ||
|
|
||
| if len(errors) > 0: | ||
| raise ValueError("\n".join(errors)) | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return trimmed_keys | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @field_validator("default_values") | ||
| @classmethod | ||
| def validate_default_values(cls, v: dict[str, str]) -> dict[str, str]: | ||
| errors = [] | ||
| keys = set() | ||
| normalized_dict = {} | ||
|
|
||
| for key, value in v.items(): | ||
| trimmed_key = key.strip() if key is not None else "" | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if trimmed_key == "": | ||
| errors.append("Key cannot be empty or contain only whitespace") | ||
| continue | ||
|
|
||
| if '.' in trimmed_key: | ||
| errors.append(f"Key '{trimmed_key}' cannot contain '.' character") | ||
| continue | ||
|
|
||
| if trimmed_key in keys: | ||
| errors.append(f"Key '{trimmed_key}' is duplicated") | ||
| continue | ||
|
|
||
| keys.add(trimmed_key) | ||
| normalized_dict[trimmed_key] = str(value) | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if len(errors) > 0: | ||
| raise ValueError("\n".join(errors)) | ||
NiveditJain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return normalized_dict | ||
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
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.