Skip to content

Commit

Permalink
Support schedule releated params for create_project
Browse files Browse the repository at this point in the history
  • Loading branch information
chezou committed Apr 20, 2024
1 parent 37d95f7 commit d503085
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
25 changes: 20 additions & 5 deletions tdworkflow/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from .schedule import Schedule, ScheduleAttempt
from .session import Session
from .task import Task
from .util import archive_files, to_iso8601
from .util import archive_files, to_iso8601, to_iso_instant
from .workflow import Workflow

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -102,7 +102,7 @@ class ProjectAPI:
str,
DefaultArg(DataType, "data"),
DefaultArg(Dict[str, Any], "_json"),
DefaultArg(Dict[str, str], "params"),
DefaultArg(Dict[str, Union[str, List[str]]], "params"),
],
PutResponse,
]
Expand Down Expand Up @@ -193,13 +193,19 @@ def create_project(
self,
project_name: str,
target_dir: str,
schedule_from: Optional[datetime] = None,
clear_schedules: Optional[List[str]] = None,
clear_schedule_all: Optional[bool] = None,
exclude_patterns: Optional[List[str]] = None,
revision: Optional[str] = None,
) -> Project:
"""Create a new project
:param project_name: Project name
:param target_dir: Target directory name
:param schedule_from: Start scheduling of new workflows from the given time instead of current time
:param clear_schedules: Clear schedules for the given workflow names
:param clear_schedule_all: Clear all schedules
:param exclude_patterns: Exclude file patterns. They are treated as regexp
patterns.
default: ["venv", ".venv", "__pycache__", ".egg-info",\
Expand All @@ -208,7 +214,16 @@ def create_project(
:return:
"""
revision = revision or str(uuid.uuid4())
params = {"project": project_name, "revision": revision}
params: Dict[str, Union[str, List[str]]] = {
"project": project_name,
"revision": revision,
}
if schedule_from:
params["schedule_from"] = to_iso_instant(schedule_from)
if clear_schedules:
params["clear_schedule"] = clear_schedules
if clear_schedule_all:
params["clear_schedule_all"] = "true"

default_excludes = [
"venv",
Expand Down Expand Up @@ -452,7 +467,7 @@ class AttemptAPI:
str,
DefaultArg(DataType, "data"),
DefaultArg(Dict[str, Any], "_json"),
DefaultArg(Dict[str, str], "params"),
DefaultArg(Dict[str, Union[str, List[str]]], "params"),
],
PutResponse,
]
Expand Down Expand Up @@ -1038,7 +1053,7 @@ def put(
path: str,
data: Optional[DataType] = None,
_json: Optional[Dict[str, Any]] = None,
params: Optional[Dict[str, str]] = None,
params: Optional[Dict[str, Union[str, List[str]]]] = None,
) -> PutResponse:
"""PUT operator for REST API
Expand Down
14 changes: 13 additions & 1 deletion tdworkflow/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def to_iso8601(dt: Optional[Union[str, datetime]]) -> str:
if isinstance(dt, datetime):
# Naive object
if not dt.tzinfo:
return dt.astimezone(timezone(timedelta(0), "UTC")).isoformat()
return dt.astimezone(timezone.utc).isoformat()
# Aware object
else:
return dt.isoformat()
Expand All @@ -58,3 +58,15 @@ def to_iso8601(dt: Optional[Union[str, datetime]]) -> str:

else:
raise ValueError("Unexpected type")


def to_iso_instant(dt: datetime) -> str:
if isinstance(dt, datetime):
return (
dt.astimezone(timezone.utc)
.isoformat(timespec="seconds")
.replace("+00:00", "Z")
)

else:
raise ValueError("Unexpected type")
2 changes: 2 additions & 0 deletions tests/resources/sample_project/main.dig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
+hello:
echo>: hello

0 comments on commit d503085

Please sign in to comment.