-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
ComputeClient
methods to submit & get tasks
Added the `.submit()`, `.get_task()`, `.get_task_batch()`, and `.get_task_group()` methods to the `ComputeClient` class.
- Loading branch information
Showing
10 changed files
with
272 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,29 @@ | ||
import uuid | ||
|
||
ENDPOINT_ID = str(uuid.uuid1()) | ||
|
||
FUNCTION_ID = str(uuid.uuid1()) | ||
FUNCTION_NAME = "howdy_world" | ||
FUNCTION_CODE = "410\n10\n04\n:gASVQAAAAAAAAACMC2hvd2R5X3dvc ..." | ||
|
||
TASK_GROUP_ID = str(uuid.uuid1()) | ||
TASK_ID = str(uuid.uuid1()) | ||
TASK_ID_2 = str(uuid.uuid1()) | ||
TASK_ARGS = "36\n00\ngASVDAAAAAAAAACMBlJvZG5leZSFlC4=\n12 ..." | ||
TASK_ARGS_2 = "36\n00\ngASVCwAAAAAAAACMBUJvYmJ5lIWULg==\n12 ..." | ||
TASK_DOC = { | ||
"task_id": TASK_ID, | ||
"status": "success", | ||
"result": "10000", | ||
"completion_t": "1677183605.212898", | ||
"details": { | ||
"os": "Linux-5.19.0-1025-aws-x86_64-with-glibc2.35", | ||
"python_version": "3.10.4", | ||
"dill_version": "0.3.5.1", | ||
"globus_compute_sdk_version": "2.3.2", | ||
"task_transitions": { | ||
"execution-start": 1692742841.843334, | ||
"execution-end": 1692742846.123456, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from globus_sdk._testing.models import RegisteredResponse, ResponseSet | ||
|
||
from ._common import TASK_DOC, TASK_ID | ||
|
||
RESPONSES = ResponseSet( | ||
metadata={"task_id": TASK_ID}, | ||
default=RegisteredResponse( | ||
service="compute", | ||
path=f"/v2/tasks/{TASK_ID}", | ||
method="GET", | ||
json=TASK_DOC, | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from responses.matchers import json_params_matcher | ||
|
||
from globus_sdk._testing.models import RegisteredResponse, ResponseSet | ||
|
||
from ._common import TASK_DOC, TASK_ID | ||
|
||
TASK_BATCH_DOC = { | ||
"response": "batch", | ||
"results": {TASK_ID: TASK_DOC}, | ||
} | ||
|
||
RESPONSES = ResponseSet( | ||
metadata={"task_id": TASK_ID}, | ||
default=RegisteredResponse( | ||
service="compute", | ||
path="/v2/tasks/batch", | ||
method="POST", | ||
json=TASK_BATCH_DOC, | ||
# Ensure task_ids is a list | ||
match=[json_params_matcher({"task_ids": [TASK_ID]})], | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from globus_sdk._testing.models import RegisteredResponse, ResponseSet | ||
|
||
from ._common import TASK_GROUP_ID, TASK_ID, TASK_ID_2 | ||
|
||
TASK_BATCH_DOC = { | ||
"taskgroup_id": TASK_GROUP_ID, | ||
"create_websockets_queue": True, | ||
"tasks": [ | ||
{"id": TASK_ID, "created_at": "2021-05-05T15:00:00.000000"}, | ||
{"id": TASK_ID_2, "created_at": "2021-05-05T15:01:00.000000"}, | ||
], | ||
} | ||
|
||
RESPONSES = ResponseSet( | ||
metadata={ | ||
"task_group_id": TASK_GROUP_ID, | ||
"task_id": TASK_ID, | ||
"task_id_2": TASK_ID_2, | ||
}, | ||
default=RegisteredResponse( | ||
service="compute", | ||
path=f"/v2/taskgroup/{TASK_GROUP_ID}", | ||
method="GET", | ||
json=TASK_BATCH_DOC, | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from globus_sdk._testing.models import RegisteredResponse, ResponseSet | ||
|
||
from ._common import ( | ||
ENDPOINT_ID, | ||
FUNCTION_ID, | ||
TASK_ARGS, | ||
TASK_ARGS_2, | ||
TASK_GROUP_ID, | ||
TASK_ID, | ||
TASK_ID_2, | ||
) | ||
|
||
REQUEST_ID = "5158de19-10b5-4deb-9d87-a86c1dec3460" | ||
|
||
SUBMIT_RESPONSE = { | ||
"request_id": REQUEST_ID, | ||
"task_group_id": TASK_GROUP_ID, | ||
"endpoint_id": ENDPOINT_ID, | ||
"tasks": { | ||
FUNCTION_ID: [TASK_ID, TASK_ID_2], | ||
}, | ||
} | ||
|
||
RESPONSES = ResponseSet( | ||
metadata={ | ||
"endpoint_id": ENDPOINT_ID, | ||
"function_id": FUNCTION_ID, | ||
"task_id": TASK_ID, | ||
"task_id_2": TASK_ID_2, | ||
"task_args": TASK_ARGS, | ||
"task_args_2": TASK_ARGS_2, | ||
"task_group_id": TASK_GROUP_ID, | ||
"request_id": REQUEST_ID, | ||
}, | ||
default=RegisteredResponse( | ||
service="compute", | ||
path=f"/v2/endpoints/{ENDPOINT_ID}/submit", | ||
method="POST", | ||
json=SUBMIT_RESPONSE, | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import uuid | ||
|
||
import pytest | ||
|
||
import globus_sdk | ||
from globus_sdk._testing import load_response | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"task_id_style", ("string", "list", "set", "uuid", "uuid_list") | ||
) | ||
def test_get_task_batch(compute_client: globus_sdk.ComputeClient, task_id_style: str): | ||
meta = load_response(compute_client.get_task_batch).metadata | ||
|
||
if task_id_style == "string": | ||
task_ids = meta["task_id"] | ||
elif task_id_style == "list": | ||
task_ids = [meta["task_id"]] | ||
elif task_id_style == "set": | ||
task_ids = {meta["task_id"]} | ||
elif task_id_style == "uuid": | ||
task_ids = uuid.UUID(meta["task_id"]) | ||
elif task_id_style == "uuid_list": | ||
task_ids = [uuid.UUID(meta["task_id"])] | ||
else: | ||
raise NotImplementedError(f"Unknown task_id_style {task_id_style}") | ||
|
||
res = compute_client.get_task_batch(task_ids=task_ids) | ||
|
||
assert res.http_status == 200 | ||
assert meta["task_id"] in res.data["results"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import globus_sdk | ||
from globus_sdk._testing import load_response | ||
|
||
|
||
def test_get_task_group(compute_client: globus_sdk.ComputeClient): | ||
meta = load_response(compute_client.get_task_group).metadata | ||
res = compute_client.get_task_group(task_group_id=meta["task_group_id"]) | ||
assert res.http_status == 200 | ||
assert meta["task_group_id"] == res.data["taskgroup_id"] | ||
assert meta["task_id"] == res.data["tasks"][0]["id"] | ||
assert meta["task_id_2"] == res.data["tasks"][1]["id"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import globus_sdk | ||
from globus_sdk._testing import load_response | ||
|
||
|
||
def test_get_task(compute_client: globus_sdk.ComputeClient): | ||
meta = load_response(compute_client.get_task).metadata | ||
res = compute_client.get_task(task_id=meta["task_id"]) | ||
assert res.http_status == 200 | ||
assert res.data["task_id"] == meta["task_id"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import globus_sdk | ||
from globus_sdk._testing import load_response | ||
|
||
|
||
def test_submit(compute_client: globus_sdk.ComputeClient): | ||
meta = load_response(compute_client.submit).metadata | ||
submit_doc = { | ||
"tasks": { | ||
meta["function_id"]: [meta["task_args"], meta["task_args_2"]], | ||
}, | ||
"task_group_id": meta["task_group_id"], | ||
"create_queue": True, | ||
"user_runtime": { | ||
"globus_compute_sdk_version": "2.29.0", | ||
"globus_sdk_version": "3.46.0", | ||
"python_version": "3.11.9", | ||
}, | ||
} | ||
|
||
res = compute_client.submit(endpoint_id=meta["endpoint_id"], data=submit_doc) | ||
|
||
assert res.http_status == 200 | ||
assert res.data["request_id"] == meta["request_id"] | ||
assert res.data["task_group_id"] == meta["task_group_id"] | ||
assert res.data["endpoint_id"] == meta["endpoint_id"] | ||
assert res.data["tasks"] == { | ||
meta["function_id"]: [meta["task_id"], meta["task_id_2"]] | ||
} |