Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a FlowsClient.get_run_definition() method #799

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Added
~~~~~

- Add a ``FlowsClient.get_run_definition()`` method. (:pr:`NUMBER`)
27 changes: 27 additions & 0 deletions src/globus_sdk/_testing/data/flows/get_run_definition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import uuid

from globus_sdk._testing import RegisteredResponse, ResponseList, ResponseSet

from ._common import RUN_ID

GET_RUN_DEFINITION = {
"flow_id": str(uuid.uuid4()),
"definition": {
"States": {"no-op": {"End": True, "Type": "Pass"}},
"StartAt": "no-op",
},
"input_schema": {},
}


RESPONSES = ResponseSet(
metadata={"run_id": RUN_ID},
default=ResponseList(
RegisteredResponse(
service="flows",
method="GET",
path=f"/runs/{RUN_ID}/definition",
json=GET_RUN_DEFINITION,
),
),
)
34 changes: 34 additions & 0 deletions src/globus_sdk/services/flows/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,40 @@ def get_run(

return self.get(f"/runs/{run_id}", query_params=query_params)

def get_run_definition(
self,
run_id: UUIDLike,
) -> GlobusHTTPResponse:
"""
Get the flow definition and input schema at the time the run was started.

:param run_id: The ID of the run to get
:type run_id: str or UUID

.. tab-set::

.. tab-item:: Example Usage

.. code-block:: python

from globus_sdk import FlowsClient

flows = FlowsClient(...)
flows.get_run_definition("581753c7-45da-43d3-ad73-246b46e7cb6b")

.. tab-item:: Example Response Data

.. expandtestfixture:: flows.get_run_definition

.. tab-item:: API Info

.. extdoclink:: Get Run Definition
:service: flows
:ref: Flows/paths/~1runs~1{run_id}~1definition/get
"""

return self.get(f"/runs/{run_id}/definition")

def cancel_run(self, run_id: UUIDLike) -> GlobusHTTPResponse:
"""
Cancel a run.
Expand Down
11 changes: 11 additions & 0 deletions tests/functional/services/flows/test_run_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
from globus_sdk._testing import get_last_request, load_response


def test_get_run_definition(flows_client):
"""Validate the HTTP method and route used to get the flow definition for a run."""

run_id = load_response(flows_client.get_run_definition).metadata["run_id"]

flows_client.get_run_definition(run_id)
request = get_last_request()
assert request.method == "GET"
assert request.url.endswith(f"/runs/{run_id}/definition")


def test_cancel_run(flows_client):
"""Verify that run cancellation requests meet expectations."""

Expand Down