Skip to content

Commit 75abfeb

Browse files
authored
Merge pull request #122 from Paperspace/PS-11581
Ps 11581
2 parents 6f116bd + d71bd3c commit 75abfeb

File tree

3 files changed

+29
-28
lines changed

3 files changed

+29
-28
lines changed

gradient/api_sdk/repositories/jobs.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from gradient import config
22
from gradient.api_sdk import serializers
3-
from .common import ListResources, CreateResource, BaseRepository, GetResource
3+
from gradient.api_sdk.clients import http_client
4+
from .common import ListResources, CreateResource, BaseRepository, GetResource, DeleteResource, StopResource
45
from ..serializers import JobSchema, LogRowSchema
56

67

@@ -106,26 +107,24 @@ def _get_client(self, use_vpc=False):
106107
return self.http_client
107108

108109

109-
class DeleteJob(GetBaseJobApiUrlMixin, BaseRepository):
110+
class DeleteJob(GetBaseJobApiUrlMixin, DeleteResource):
110111

111112
def get_request_url(self, **kwargs):
112-
return "/job/{}/destroy/".format(kwargs.get("id_"))
113+
return "/jobs/{}/destroy".format(kwargs.get("id"))
113114

114-
def delete(self, id_, **kwargs):
115-
url = self.get_request_url(id_=id_)
116-
response = self.client.post(url)
117-
self._validate_response(response)
115+
def _send_request(self, client, url, json_data=None):
116+
response = client.post(url, json=json_data)
117+
return response
118118

119119

120-
class StopJob(GetBaseJobApiUrlMixin, BaseRepository):
120+
class StopJob(GetBaseJobApiUrlMixin, StopResource):
121121

122122
def get_request_url(self, **kwargs):
123-
return "/job/{}/stop/".format(kwargs.get('id_'))
123+
return "/jobs/{}/stop".format(kwargs.get('id'))
124124

125-
def stop(self, id_, **kwargs):
126-
url = self.get_request_url(id_=id_)
127-
response = self.client.post(url)
128-
self._validate_response(response)
125+
def _send_request(self, client, url, json_data=None):
126+
response = client.post(url, json=json_data)
127+
return response
129128

130129

131130
class ListJobArtifacts(GetBaseJobApiUrlMixin, ListResources):
@@ -152,20 +151,22 @@ def _get_request_params(self, kwargs):
152151
return params
153152

154153

155-
class DeleteJobArtifacts(GetBaseJobApiUrlMixin, BaseRepository):
154+
class DeleteJobArtifacts(GetBaseJobApiUrlMixin, DeleteResource):
156155
VALIDATION_ERROR_MESSAGE = "Failed to delete resource"
157156

158157
def get_request_url(self, **kwargs):
159-
return "/jobs/{}/artifactsDestroy/".format(kwargs.get("id_"))
160-
161-
def delete(self, id_, **kwargs):
162-
url = self.get_request_url(id_=id_)
163-
164-
params = self._get_request_params(kwargs)
165-
166-
client = self._get_client()
167-
response = client.post(url, json=kwargs.get("json"), params=params)
168-
self._validate_response(response)
158+
return "/jobs/{}/artifactsDestroy".format(kwargs.get("id"))
159+
160+
def _send(self, url, use_vpc=False, **kwargs):
161+
client = self._get_client(use_vpc=use_vpc)
162+
params_data = self._get_request_params(kwargs)
163+
response = self._send_request(client, url, params_data=params_data)
164+
gradient_response = http_client.GradientResponse.interpret_response(response)
165+
return gradient_response
166+
167+
def _send_request(self, client, url, params_data=None):
168+
response = client.post(url, params=params_data)
169+
return response
169170

170171
def _get_request_params(self, kwargs):
171172
filters = dict()

gradient/cli/jobs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def jobs_group():
3232
help="Delete job with given ID",
3333
)
3434
@api_key_option
35-
def delete_job(job_id, api_key=None):
35+
def delete_job(job_id, api_key):
3636
command = jobs_commands.DeleteJobCommand(api_key=api_key)
3737
command.execute(job_id)
3838

tests/functional/test_jobs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def test_should_send_valid_post_request_when_destroying_artifacts_with_files_spe
311311
"some_key"])
312312

313313
assert result.exit_code == 0, result.exc_info
314-
post_patched.assert_called_with("{}/jobs/{}/artifactsDestroy/".format(self.URL, job_id),
314+
post_patched.assert_called_with("{}/jobs/{}/artifactsDestroy".format(self.URL, job_id),
315315
files=None,
316316
headers=self.EXPECTED_HEADERS_WITH_CHANGED_API_KEY,
317317
json=None,
@@ -324,7 +324,7 @@ def test_should_send_valid_post_request_when_destroying_artifacts_without_files_
324324
job_id = "some_job_id"
325325
result = self.runner.invoke(cli.cli, ["jobs", "artifacts", "destroy", job_id, "--apiKey", "some_key"])
326326

327-
post_patched.assert_called_with("{}/jobs/{}/artifactsDestroy/".format(self.URL, job_id),
327+
post_patched.assert_called_with("{}/jobs/{}/artifactsDestroy".format(self.URL, job_id),
328328
files=None,
329329
headers=self.EXPECTED_HEADERS_WITH_CHANGED_API_KEY,
330330
json=None,
@@ -340,7 +340,7 @@ def test_should_read_options_from_yaml_file(self, post_patched, jobs_artifacts_d
340340
result = self.runner.invoke(cli.cli, command)
341341

342342
assert result.exit_code == 0, result.exc_info
343-
post_patched.assert_called_with("{}/jobs/some_id/artifactsDestroy/".format(self.URL),
343+
post_patched.assert_called_with("{}/jobs/some_id/artifactsDestroy".format(self.URL),
344344
files=None,
345345
headers=self.EXPECTED_HEADERS_WITH_CHANGED_API_KEY,
346346
json=None,

0 commit comments

Comments
 (0)