Skip to content
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
49 changes: 25 additions & 24 deletions gradient/api_sdk/repositories/jobs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from gradient import config
from gradient.api_sdk import serializers
from .common import ListResources, CreateResource, BaseRepository, GetResource
from gradient.api_sdk.clients import http_client
from .common import ListResources, CreateResource, BaseRepository, GetResource, DeleteResource, StopResource
from ..serializers import JobSchema, LogRowSchema


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


class DeleteJob(GetBaseJobApiUrlMixin, BaseRepository):
class DeleteJob(GetBaseJobApiUrlMixin, DeleteResource):

def get_request_url(self, **kwargs):
return "/job/{}/destroy/".format(kwargs.get("id_"))
return "/jobs/{}/destroy".format(kwargs.get("id"))

def delete(self, id_, **kwargs):
url = self.get_request_url(id_=id_)
response = self.client.post(url)
self._validate_response(response)
def _send_request(self, client, url, json_data=None):
response = client.post(url, json=json_data)
return response


class StopJob(GetBaseJobApiUrlMixin, BaseRepository):
class StopJob(GetBaseJobApiUrlMixin, StopResource):

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

def stop(self, id_, **kwargs):
url = self.get_request_url(id_=id_)
response = self.client.post(url)
self._validate_response(response)
def _send_request(self, client, url, json_data=None):
response = client.post(url, json=json_data)
return response


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


class DeleteJobArtifacts(GetBaseJobApiUrlMixin, BaseRepository):
class DeleteJobArtifacts(GetBaseJobApiUrlMixin, DeleteResource):
VALIDATION_ERROR_MESSAGE = "Failed to delete resource"

def get_request_url(self, **kwargs):
return "/jobs/{}/artifactsDestroy/".format(kwargs.get("id_"))

def delete(self, id_, **kwargs):
url = self.get_request_url(id_=id_)

params = self._get_request_params(kwargs)

client = self._get_client()
response = client.post(url, json=kwargs.get("json"), params=params)
self._validate_response(response)
return "/jobs/{}/artifactsDestroy".format(kwargs.get("id"))

def _send(self, url, use_vpc=False, **kwargs):
client = self._get_client(use_vpc=use_vpc)
params_data = self._get_request_params(kwargs)
response = self._send_request(client, url, params_data=params_data)
gradient_response = http_client.GradientResponse.interpret_response(response)
return gradient_response

def _send_request(self, client, url, params_data=None):
response = client.post(url, params=params_data)
return response

def _get_request_params(self, kwargs):
filters = dict()
Expand Down
2 changes: 1 addition & 1 deletion gradient/cli/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def jobs_group():
help="Delete job with given ID",
)
@api_key_option
def delete_job(job_id, api_key=None):
def delete_job(job_id, api_key):
command = jobs_commands.DeleteJobCommand(api_key=api_key)
command.execute(job_id)

Expand Down
6 changes: 3 additions & 3 deletions tests/functional/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def test_should_send_valid_post_request_when_destroying_artifacts_with_files_spe
"some_key"])

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

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

assert result.exit_code == 0, result.exc_info
post_patched.assert_called_with("{}/jobs/some_id/artifactsDestroy/".format(self.URL),
post_patched.assert_called_with("{}/jobs/some_id/artifactsDestroy".format(self.URL),
files=None,
headers=self.EXPECTED_HEADERS_WITH_CHANGED_API_KEY,
json=None,
Expand Down