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 58b37d6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
11 changes: 10 additions & 1 deletion 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 @@ -193,6 +193,9 @@ def create_project(
self,
project_name: str,
target_dir: str,
schedule_from: Optional[datetime],
clear_schedule: Optional[List[str]] = None,
clear_schedule_all: Optional[bool] = None,
exclude_patterns: Optional[List[str]] = None,
revision: Optional[str] = None,
) -> Project:
Expand All @@ -209,6 +212,12 @@ def create_project(
"""
revision = revision or str(uuid.uuid4())
params = {"project": project_name, "revision": revision}
if schedule_from:
params["schedule_from"] = to_iso_instant(schedule_from)
if clear_schedule:
params["clear_schedule"] = clear_schedule
if clear_schedule_all:
params["clear_schedule_all"] = "true"

default_excludes = [
"venv",
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 58b37d6

Please sign in to comment.