Skip to content

Commit 57de998

Browse files
author
Bruno Grande
authored
Merge pull request #18 from Sage-Bionetworks-Workflows/bgrande/orca-210/resume-workflows
[ORCA-210] Add support for resuming workflows in NextflowTowerOps
2 parents f1a4b33 + ccd3a57 commit 57de998

File tree

12 files changed

+875
-176
lines changed

12 files changed

+875
-176
lines changed

src/orca/services/nextflowtower/client.py

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ def request_json(self, method: str, path: str, **kwargs) -> dict[str, Any]:
8383
A dictionary from deserializing the JSON response.
8484
"""
8585
response = self.request(method, path, **kwargs)
86-
response.raise_for_status()
86+
try:
87+
response.raise_for_status()
88+
except HTTPError as e:
89+
# Add extra context if possible
90+
raise HTTPError(response.text) from e
8791
return response.json()
8892

8993
def request_paged(self, method: str, path: str, **kwargs) -> dict[str, Any]:
@@ -318,22 +322,50 @@ def launch_workflow(
318322
"""
319323
path = "/workflow/launch"
320324
params = self.generate_params(workspace_id)
321-
payload = launch_info.to_dict()
325+
payload = launch_info.to_json()
322326
json = self.post(path, params=params, json=payload)
323327
return self.unwrap(json, "workflowId")
324328

325-
def get_workflow(self, workspace_id: int, workflow_id: str) -> dict:
326-
"""Gets available information about a workflow run
329+
def get_workflow(
330+
self,
331+
workflow_id: str,
332+
workspace_id: Optional[int] = None,
333+
) -> models.Workflow:
334+
"""Get information about a workflow run.
327335
328336
Attributes:
329-
workspace_id (int): The ID number of the workspace the workflow
330-
exists within.
331-
workflow_id (str): The ID number for a workflow run to get
332-
information about.
337+
workflow_id: The ID number for a workflow run to get
338+
information about.
339+
workspace_id: The ID number of the workspace the workflow
340+
exists within. Defaults to None.
333341
334342
Returns:
335-
response (dict): Dictionary containing information about the workflow run
343+
Workflow instance.
336344
"""
337345
path = f"/workflow/{workflow_id}"
338-
json = self.get(path=path, params={"workspaceId": workspace_id})
339-
return json
346+
params = self.generate_params(workspace_id)
347+
json = self.get(path=path, params=params)
348+
unwrapped = self.unwrap(json, "workflow")
349+
return models.Workflow.from_json(unwrapped)
350+
351+
def list_workflows(
352+
self,
353+
search_filter: Optional[str] = None,
354+
workspace_id: Optional[int] = None,
355+
) -> list[models.Workflow]:
356+
"""List available workflows that match search filter.
357+
358+
Attributes:
359+
search_filter: A Nextflow Tower search query, as you would
360+
compose it in the runs search bar. Defaults to None.
361+
workspace_id: The ID number of the workspace the workflow
362+
exists within. Defaults to None.
363+
364+
Returns:
365+
List of workflow instances.
366+
"""
367+
path = "/workflow"
368+
params = self.generate_params(workspace_id, search=search_filter)
369+
json = self.get(path=path, params=params)
370+
items = self.unwrap(json, "workflows")
371+
return [models.Workflow.from_json(item["workflow"]) for item in items]

0 commit comments

Comments
 (0)