-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(workflow): refactored entire workflow core
- Loading branch information
Showing
12 changed files
with
667 additions
and
462 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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,2 @@ | ||
WORKFLOW_TOKEN="abc123" | ||
WORKFLOW_SITES=chime,local |
This file contains 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,2 +1,2 @@ | ||
"""Top-level imports for Tasks API.""" | ||
from .work import Work # noqa: F401 | ||
from .work.work import Work # noqa: F401s |
This file contains 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 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
Empty file.
This file contains 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,81 @@ | ||
"""Work Object Configuration.""" | ||
from typing import List, Literal, Optional | ||
|
||
from pydantic import BaseModel, ConfigDict, Field | ||
|
||
|
||
class Archive(BaseModel): | ||
"""Archive Configuration. | ||
This class is used to configure the archive strategy for the work. | ||
Args: | ||
BaseModel (BaseModel): Pydantic BaseModel. | ||
Attributes: | ||
results (bool): Archive results for the work. | ||
products (Literal["pass", "copy", "move", "delete", "upload"]): | ||
Archive strategy for the products. | ||
plots (Literal["pass", "copy", "move", "delete", "upload"]): | ||
Archive strategy for the plots. | ||
logs (Literal["pass", "copy", "move", "delete", "upload"]): | ||
Archive strategy for the logs. | ||
""" | ||
|
||
model_config = ConfigDict(validate_default=True, validate_assignment=True) | ||
|
||
results: bool = Field( | ||
default=True, | ||
description="Archive results for the work.", | ||
) | ||
products: Literal["pass", "copy", "move", "delete", "upload"] = Field( | ||
default="copy", | ||
description="Archive strategy for the products.", | ||
) | ||
plots: Literal["pass", "copy", "move", "delete", "upload"] = Field( | ||
default="copy", | ||
description="Archive strategy for the plots.", | ||
) | ||
logs: Literal["pass", "copy", "move", "delete", "upload"] = Field( | ||
default="move", | ||
description="Archive strategy for the logs.", | ||
) | ||
|
||
|
||
class Config(BaseModel): | ||
"""Work Object Configuration. | ||
This class is used to configure the work object. | ||
Args: | ||
BaseModel (BaseModel): Pydantic BaseModel. | ||
""" | ||
|
||
model_config = ConfigDict(validate_default=True, validate_assignment=True) | ||
|
||
archive: Archive = Archive() | ||
metrics: bool = Field( | ||
default=False, | ||
description="Generate metrics from work lifecycle.", | ||
) | ||
parent: Optional[str] = Field( | ||
default=None, | ||
description="ID of the parent workflow pipeline.", | ||
json_schema_extra={"examples": ["5f9b5c5d7b54b5a9c5e5b5c5"]}, | ||
) | ||
orgs: List[str] = Field( | ||
default=["chimefrb"], | ||
description=""" | ||
List of organization[s] the work belongs to. | ||
Maps to the Github organization. | ||
""", | ||
json_schema_extra={"examples": ["chimefrb", "chime-sps"]}, | ||
) | ||
teams: Optional[List[str]] = Field( | ||
default=None, | ||
description=""" | ||
List of team[s] the work belongs to. | ||
Maps to the Github team within the organization. | ||
""", | ||
json_schema_extra={"example": ["frb-tsars", "frb-ops"]}, | ||
) |
This file contains 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,81 @@ | ||
"""Notification Configuration.""" | ||
from typing import Any, Dict, List, Optional | ||
|
||
from pydantic import BaseModel, ConfigDict, Field, StrictStr | ||
|
||
|
||
class Slack(BaseModel): | ||
"""Slack Configuration. | ||
This class is used to configure the slack notification strategy for the work. | ||
Args: | ||
BaseModel (BaseModel): Pydantic BaseModel. | ||
Attributes: | ||
channel_id (str): Slack channel to send notifications to. | ||
member_ids (List[str]): Slack members to send notifications to. | ||
message (str): Slack message to send notifications with. | ||
results (bool): Send slack notifications with the work results. | ||
products (bool): Send slack notifications with the work product links. | ||
plots (bool): Send slack notifications with the work plot links. | ||
blocks (Dict[str, Any]): Slack blocks to send notifications with. | ||
reply (Dict[str, Any]): Status of the slack notification. | ||
""" | ||
|
||
model_config = ConfigDict( | ||
title="Slack Configuration", | ||
validate_default=True, | ||
validate_assignment=True, | ||
extra="forbid", | ||
) | ||
|
||
channel_id: Optional[StrictStr] = Field( | ||
default=None, | ||
description="Slack channel to send notifications to.", | ||
examples=["C01JYQZQX0Y"], | ||
) | ||
member_ids: Optional[List[StrictStr]] = Field( | ||
default=None, | ||
description="Slack members to send notifications to.", | ||
examples=[["U01JYQZQX0Y"]], | ||
) | ||
message: Optional[StrictStr] = Field( | ||
default=None, | ||
description="Slack message to send notifications with.", | ||
examples=["Hello World!"], | ||
) | ||
results: Optional[bool] = Field( | ||
default=None, | ||
description="Send slack notifications with the work results.", | ||
) | ||
products: Optional[bool] = Field( | ||
default=None, | ||
description="Send slack notifications with the work product links.", | ||
) | ||
plots: Optional[bool] = Field( | ||
default=None, | ||
description="Send slack notifications with the work plot links.", | ||
) | ||
blocks: Optional[Dict[str, Any]] = Field( | ||
default=None, | ||
description="Slack blocks to send notifications with.", | ||
) | ||
reply: Optional[Dict[str, Any]] = Field( | ||
default=None, | ||
description="Status of the slack notification.", | ||
examples=[{"ok": True}], | ||
) | ||
|
||
|
||
class Notify(BaseModel): | ||
"""Work Object Notification Configuration. | ||
Args: | ||
BaseModel (BaseModel): Pydantic BaseModel. | ||
Attributes: | ||
slack (Slack): Send slack notifications for the work. | ||
""" | ||
|
||
slack: Slack = Slack() |
This file contains 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,70 @@ | ||
"""Workflow Settings.""" | ||
from typing import List, Optional | ||
|
||
from pydantic import AliasChoices, Field, SecretStr, field_validator | ||
from pydantic_settings import BaseSettings, SettingsConfigDict | ||
|
||
|
||
class Settings(BaseSettings): | ||
"""Workflow Settings. | ||
Args: | ||
BaseSettings (BaseSettings): Pydantic BaseSettings. | ||
Returns: | ||
Settings: Workflow settings. | ||
""" | ||
|
||
model_config = SettingsConfigDict( | ||
env_prefix="WORKFLOW_", | ||
env_file="workflow.env", | ||
env_file_encoding="utf-8", | ||
env_nested_delimiter="__", | ||
secrets_dir="/run/secrets", | ||
str_to_lower=True, | ||
case_sensitive=True, | ||
extra="ignore", | ||
) | ||
|
||
token: Optional[SecretStr] = Field( | ||
default=None, | ||
validation_alias=AliasChoices( | ||
"WORKFLOW_TOKEN", | ||
"GITHUB_TOKEN", | ||
"GITHUB_PAT", | ||
"GITHUB_ACCESS_TOKEN", | ||
"GITHUB_PERSONAL_ACCESS_TOKEN", | ||
), | ||
) | ||
|
||
sites: Optional[List[str]] = Field( | ||
default=None, | ||
validation_alias=AliasChoices( | ||
"SITES", | ||
"WORKFLOW_SITES", | ||
), | ||
) | ||
|
||
tags: Optional[List[str]] = Field( | ||
default=None, | ||
validation_alias=AliasChoices( | ||
"TAGS", | ||
"WORKFLOW_TAGS", | ||
), | ||
) | ||
|
||
@field_validator("sites", mode="before") | ||
def sites_validator(cls, sites: str) -> List[str]: | ||
"""Sites Validator. | ||
Args: | ||
sites (str): Value of the sites setting. | ||
Returns: | ||
List[str]: List of sites. | ||
""" | ||
return sites.split(",") | ||
|
||
|
||
if __name__ == "__main__": | ||
print(Settings().model_dump()) # type: ignore |
Oops, something went wrong.