Skip to content

Commit

Permalink
feat: Follow up recent digdag update treasure-data/digdag#1697
Browse files Browse the repository at this point in the history
  • Loading branch information
chezou committed May 25, 2022
1 parent 793a3bb commit c0cfdd1
Showing 1 changed file with 63 additions and 17 deletions.
80 changes: 63 additions & 17 deletions tdworkflow/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,41 @@


class WorkflowAPI:
def workflows(self) -> List[Workflow]:
def workflows(
self,
name_pattern: Optional[str] = None,
search_project_name: bool = False,
order: Optional[str] = None,
count: Optional[int] = None,
last_id: Optional[int] = None,
) -> List[Workflow]:
"""List worlfows
:param name_pattern: Name pattern to be partially matched
:type name_pattern: Optional[str], optional
:param search_project_name: Flag to use name_pattern to search partial project name. Default False
:type search_project_name: bool
:param order: Sort order. 'asc' or 'dsc'. Default 'asc'
:type order: Optional[str]
:param count: Number of workflows to return
:type count: Optional[int], optional
:param last_id: List workflows whose id is grater than this id for pagination.
:type last_id: Optional[int], optional
:return: List of Workflow
:rtype: List[Workflow]
"""
res = self.get("workflows")
params = {}
if name_pattern:
params["name_pattern"] = name_pattern
if search_project_name:
params["search_project_name"] = search_project_name
if order:
params["order"] = order
if count:
params["count"] = count
if last_id:
params["last_id"] = last_id
res = self.get("workflows", params=params)
if len(res) > 0:
return [Workflow.from_api_repr(**wf) for wf in res["workflows"]]
else:
Expand Down Expand Up @@ -66,19 +94,37 @@ def project(self, project: Union[int, Project]) -> Project:
r = self.get(f"projects/{project_id}")
return Project.from_api_repr(**r)

def projects(self, name: Optional[str] = None) -> List[Project]:
def projects(
self,
name: Optional[str] = None,
name_pattern: Optional[str] = None,
count: Optional[int] = None,
last_id: Optional[int] = None,
) -> List[Project]:
"""List projects
:param name: Project name
:type name: Optional[str], optional
:param name_pattern: Name pattern to be partially matched
:type name_pattern: Optional[str], optional
:param count: Number of projects to return
:type count: Optional[int], optional
:param last_id: List projects whose id is grater than this id for pagination.
:type last_id: Optional[int], optional
:return: List of Project
:rtype: List[Project]
"""
params = None
params = {}
if name:
params = {"name": name}
params["name"] = name
if name_pattern:
params["name_pattern"] = name_pattern
if count:
params["count"] = count
if last_id:
params["last_id"] = last_id

res = self.get(f"projects", params=params)
res = self.get("projects", params=params)
if res:
return [Project.from_api_repr(**proj) for proj in res["projects"]]
else:
Expand Down Expand Up @@ -228,7 +274,7 @@ def project_schedules(
:param project: Project ID or project object
:param workflow: Workflow name or Workflow object
:param last_id: Last ID
:param last_id: List schedules whose id is grater than this id for pagination
:return: List of Schedule
"""
params = {}
Expand Down Expand Up @@ -343,8 +389,8 @@ def project_sessions(
:param project: Project ID or Project object
:param workflow: Workflow name or Workflow object
:param last_id: Last ID
:param page_size: Page size
:param last_id: List sessions whose id is grater than this id for pagination
:param page_size: Number of sessions to return
:return: List of Session
"""
params = {}
Expand Down Expand Up @@ -380,11 +426,11 @@ def attempts(
:type project: Optional[Union[str, Project]]
:param workflow: Workflow name or Workflow object, optional
:type workflow: Optional[Union[str, Workflow]]
:param include_retried: Flag to include retried
:param include_retried: List more than 1 attempts per session
:type include_retried: Optional[bool]
:param last_id: Last ID
:param last_id: List attempts whose id is grater than this id for pagination
:type last_id: Optional[int]
:param page_size: Page size
:param page_size: Number of attempts to return
:type page_size: Optional[int]
:return: List of Attempt object
:rtype: List[Attempt]
Expand Down Expand Up @@ -528,7 +574,7 @@ class ScheduleAPI:
def schedules(self, last_id: Optional[int] = None) -> List[Schedule]:
"""List schedules
:param last_id: Last ID
:param last_id: List schedules whose id is grater than this id for pagination.
:return: List of Schedule
"""
r = self.get("schedules", params={"last_id": last_id})
Expand Down Expand Up @@ -649,8 +695,8 @@ def sessions(
) -> List[Session]:
"""List sessions
:param last_id: Last ID
:param page_size: Page size
:param last_id: List sessions whose id is grater than this id for pagination
:param page_size: Number of sessions to return
:return: List of Session
"""
params = {}
Expand Down Expand Up @@ -687,8 +733,8 @@ def session_attempts(
"""Get attempts of a session
:param session: Session ID or Session object
:param last_id: Last ID
:param page_size: Page size
:param last_id: List attempts whose id is grater than this id for pagination
:param page_size: Number of attempts to return
:return: List of Attempt
"""
params = {}
Expand Down

0 comments on commit c0cfdd1

Please sign in to comment.