Skip to content

Commit ec6e211

Browse files
authored
add get-submission to the cli (#60)
1 parent 293ffff commit ec6e211

File tree

6 files changed

+64
-2
lines changed

6 files changed

+64
-2
lines changed

sync/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""Library for leveraging the power of Sync"""
2-
__version__ = "0.4.11"
2+
__version__ = "0.4.12"
33

44
TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"

sync/api/projects.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,21 @@ def get_project_recommendation(project_id: str, recommendation_id: str) -> Respo
395395
return Response(**response)
396396

397397
return Response(result=response["result"])
398+
399+
400+
def get_project_submission(project_id: str, submission_id: str) -> Response[dict]:
401+
"""Get a specific submission for a project id
402+
403+
:param project_id: project ID
404+
:type project_id: str
405+
:param submission_id: submission ID
406+
:type submission_id: str
407+
:return: submission object
408+
:rtype: Response[dict]
409+
"""
410+
response = get_default_client().get_project_submission(project_id, submission_id)
411+
412+
if response.get("error"):
413+
return Response(**response)
414+
415+
return Response(result=response["result"])

sync/cli/_databricks.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
import click
44
import orjson
55

6-
from sync.api.projects import create_project_recommendation, get_project_recommendation
6+
from sync.api.projects import (
7+
create_project_recommendation,
8+
get_project_recommendation,
9+
get_project_submission,
10+
)
711
from sync.cli.util import validate_project
812
from sync.config import CONFIG
913
from sync.models import DatabricksComputeType, DatabricksPlanType, Platform, Preference
@@ -190,6 +194,7 @@ def create_recommendation(project: dict):
190194
@click.argument("project", callback=validate_project)
191195
@click.argument("recommendation-id")
192196
def get_recommendation(project: dict, recommendation_id: str):
197+
"""Get a project recommendation"""
193198
rec_response = get_project_recommendation(project["id"], recommendation_id)
194199
recommendation = rec_response.result
195200
if recommendation:
@@ -206,6 +211,27 @@ def get_recommendation(project: dict, recommendation_id: str):
206211
click.echo(f"Failed to get recommendation. {rec_response.error}", err=True)
207212

208213

214+
@click.command
215+
@click.argument("project", callback=validate_project)
216+
@click.argument("submission-id")
217+
def get_submission(project: dict, submission_id: str):
218+
"""Get a project submission"""
219+
sub_response = get_project_submission(project["id"], submission_id)
220+
submission = sub_response.result
221+
if submission:
222+
if submission["state"] == "FAILURE":
223+
click.echo("Submission generation failed.", err=True)
224+
else:
225+
click.echo(
226+
orjson.dumps(
227+
submission,
228+
option=orjson.OPT_INDENT_2 | orjson.OPT_NAIVE_UTC | orjson.OPT_UTC_Z,
229+
)
230+
)
231+
else:
232+
click.echo(f"Failed to get submission. {sub_response.error}", err=True)
233+
234+
209235
@click.command
210236
@click.argument("run-id")
211237
@click.option("--plan", type=click.Choice(DatabricksPlanType), default=DatabricksPlanType.STANDARD)

sync/cli/awsdatabricks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
create_submission,
1010
get_cluster_report,
1111
get_recommendation,
12+
get_submission,
1213
monitor_cluster,
1314
run_job,
1415
run_prediction,
@@ -30,6 +31,7 @@ def aws_databricks(ctx: click.Context):
3031
aws_databricks.add_command(create_submission)
3132
aws_databricks.add_command(create_recommendation)
3233
aws_databricks.add_command(get_recommendation)
34+
aws_databricks.add_command(get_submission)
3335
aws_databricks.add_command(apply_recommendation)
3436
aws_databricks.add_command(get_cluster_report)
3537
aws_databricks.add_command(apply_prediction)

sync/cli/azuredatabricks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
create_submission,
1010
get_cluster_report,
1111
get_recommendation,
12+
get_submission,
1213
monitor_cluster,
1314
run_job,
1415
run_prediction,
@@ -30,6 +31,7 @@ def azure_databricks(ctx: click.Context):
3031
azure_databricks.add_command(create_submission)
3132
azure_databricks.add_command(create_recommendation)
3233
azure_databricks.add_command(get_recommendation)
34+
azure_databricks.add_command(get_submission)
3335
azure_databricks.add_command(apply_recommendation)
3436
azure_databricks.add_command(get_cluster_report)
3537
azure_databricks.add_command(apply_prediction)

sync/clients/sync.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,20 @@ def get_project_recommendation(self, project_id: str, recommendation_id: str) ->
144144
)
145145
)
146146

147+
def get_project_submissions(self, project_id: str, params: dict = None) -> dict:
148+
return self._send(
149+
self._client.build_request(
150+
"GET", f"/v1/projects/{project_id}/submissions", params=params
151+
)
152+
)
153+
154+
def get_project_submission(self, project_id: str, submission_id: str) -> dict:
155+
return self._send(
156+
self._client.build_request(
157+
"GET", f"/v1/projects/{project_id}/submissions/{submission_id}"
158+
)
159+
)
160+
147161
def create_workspace_config(self, workspace_id: str, **config) -> dict:
148162
headers, content = encode_json(config)
149163
return self._send(

0 commit comments

Comments
 (0)