Skip to content

Commit 2925c3f

Browse files
committed
Add build job invalidation apis
1 parent 458fd52 commit 2925c3f

File tree

7 files changed

+86
-3
lines changed

7 files changed

+86
-3
lines changed

polyaxon_client/api/build_job.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,28 @@ def create_code_reference(self,
152152
e=e, log_message='Error while creating build coderef.')
153153
return None
154154

155+
def invalidate(self,
156+
username,
157+
project_name,
158+
job_id,
159+
background=False):
160+
request_url = self.build_url(self._get_http_url(),
161+
username,
162+
project_name,
163+
'builds',
164+
job_id,
165+
'invalidate')
166+
if background:
167+
self.transport.async_post(request_url)
168+
return None
169+
170+
try:
171+
return self.transport.post(request_url)
172+
except PolyaxonClientException as e:
173+
self.transport.handle_exception(
174+
e=e, log_message='Error while invalidating build.')
175+
return None
176+
155177
def send_logs(self,
156178
username,
157179
project_name,

polyaxon_client/api/project.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,22 @@ def list_builds(self, username, project_name, query=None, sort=None, page=1):
359359
self.transport.handle_exception(e=e, log_message='Error while retrieving build jobs.')
360360
return []
361361

362+
def invalidate_builds(self, username, project_name, background=False):
363+
"""Invalidate all build jobs related to this project."""
364+
request_url = self.build_url(
365+
self._get_http_url(), username, project_name, 'builds', 'invalidate')
366+
367+
if background:
368+
self.transport.async_post(request_url)
369+
return None
370+
371+
try:
372+
return self.transport.post(request_url)
373+
except PolyaxonClientException as e:
374+
self.transport.handle_exception(
375+
e=e, log_message='Error while invalidating builds.')
376+
return None
377+
362378
def create_build(self, username, project_name, build_config, background=False):
363379
build_config = self.validate_config(config=build_config, config_schema=BuildJobConfig)
364380
request_url = self.build_url(self._get_http_url(), username, project_name, 'builds')

polyaxon_client/tracking/contrib/fastai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import absolute_import, division, print_function
33

4+
from polyaxon_client import settings
45
from polyaxon_client.exceptions import PolyaxonClientException
56
from polyaxon_client.tracking import Experiment
6-
from polyaxon_client import settings
77

88
try:
99
from fastai.callbacks import TrackerCallback

polyaxon_client/tracking/contrib/keras.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import absolute_import, division, print_function
33

4+
from polyaxon_client import settings
45
from polyaxon_client.exceptions import PolyaxonClientException
56
from polyaxon_client.tracking import Experiment
6-
from polyaxon_client import settings
77

88
try:
99
from keras.callbacks import Callback

polyaxon_client/tracking/contrib/logging_tensor_hook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import absolute_import, division, print_function
33

4+
from polyaxon_client import settings
45
from polyaxon_client.exceptions import PolyaxonClientException
56
from polyaxon_client.tracking import Experiment
6-
from polyaxon_client import settings
77

88
try:
99
from tensorflow.train import LoggingTensorHook

tests/test_api/test_build_job.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,29 @@ def test_stop_build(self):
242242
'username', 'project_name', 1, background=True),
243243
method='post')
244244

245+
@httpretty.activate
246+
def test_invalidate_build(self):
247+
httpretty.register_uri(
248+
httpretty.POST,
249+
BaseApiHandler.build_url(
250+
self.api_config.base_url,
251+
'/',
252+
'username',
253+
'project_name',
254+
'builds',
255+
1,
256+
'invalidate'),
257+
content_type='application/json',
258+
status=200)
259+
result = self.api_handler.invalidate('username', 'project_name', 1)
260+
assert result.status_code == 200
261+
262+
# Async
263+
self.assert_async_call(
264+
api_handler_call=lambda: self.api_handler.invalidate(
265+
'username', 'project_name', 1, background=True),
266+
method='post')
267+
245268
@httpretty.activate
246269
def test_bookmark_build(self):
247270
httpretty.register_uri(

tests/test_api/test_project.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,28 @@ def test_create_build(self):
974974
'user', 'project', obj.to_dict(), background=True),
975975
method='post')
976976

977+
@httpretty.activate
978+
def test_invalidate_builds(self):
979+
httpretty.register_uri(
980+
httpretty.POST,
981+
BaseApiHandler.build_url(
982+
self.api_config.base_url,
983+
'/',
984+
'username',
985+
'project_name',
986+
'builds',
987+
'invalidate'),
988+
content_type='application/json',
989+
status=200)
990+
result = self.api_handler.invalidate_builds('username', 'project_name')
991+
assert result.status_code == 200
992+
993+
# Async
994+
self.assert_async_call(
995+
api_handler_call=lambda: self.api_handler.invalidate_builds(
996+
'username', 'project_name', background=True),
997+
method='post')
998+
977999
@httpretty.activate
9781000
def test_start_tensorboard(self):
9791001
httpretty.register_uri(

0 commit comments

Comments
 (0)