Skip to content

Commit 02cb7de

Browse files
authored
feat: add job search and archive (#44)
SDK now allows to search jobs by name and archive a list of jobs by given id list. Co-authored-by: Pablo <pjestradac@gmail.com>
1 parent 616f6f2 commit 02cb7de

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

sdk/diffgram/core/core.py

-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def __init__(
4848
if host is None:
4949
if self.debug is True:
5050
self.host = "http://127.0.0.1:8085"
51-
print("Debug", __version__)
5251
elif self.staging is True:
5352
self.host = "https://20200110t142358-dot-walrus-dot-diffgram-001.appspot.com/"
5453
else:
@@ -79,7 +78,6 @@ def __init__(
7978

8079
if init_default_directory is True:
8180
self.set_default_directory(directory = self.directory)
82-
print("Default directory set:", self.directory_id)
8381

8482
if refresh_local_label_dict is True:
8583
self.get_label_file_dict()

sdk/diffgram/file/file_constructor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def from_blob_path(self,
148148
:param frame_packet_map:
149149
:return:
150150
"""
151-
if self.client.default_directory:
151+
if not self.client.default_directory:
152152
raise Exception("Directory not set. call set_default_directory() to set upload directory.")
153153
directory_id = self.client.directory_id
154154
name = file_name

sdk/diffgram/file/view.py

-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,5 @@ def get_label_file_dict(self, schema_id = None, use_session = True):
5656
data = response.json()
5757
if data["log"]["success"] == True:
5858
self.name_to_file_id = data["name_to_file_id"]
59-
print("Loaded schema")
6059
else:
6160
raise Exception(data["log"]["errors"])

sdk/diffgram/job/job.py

+28-2
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,17 @@ def new(self,
239239
return job
240240

241241
def list(self,
242-
limit = 10,
243-
status = "All",
242+
limit = 100,
243+
status = ["All"],
244+
name = None,
244245
tags = []):
246+
"""
247+
248+
:param limit:
249+
:param status: a list with any of the values: ["All", "draft", "active", "complete", "cancelled"]
250+
:param tags:
251+
:return:
252+
"""
245253

246254
# Example usage print(project.job.list().json())
247255
tag_id_list = None
@@ -259,6 +267,7 @@ def list(self,
259267
{
260268
"limit": limit,
261269
"data_mode": "with_tags",
270+
"search": name,
262271
"status": status,
263272
"tag_list": tag_id_list,
264273
"project_string_id": self.client.project_string_id
@@ -348,6 +357,23 @@ def guide_update(
348357

349358
return False
350359

360+
def archive_jobs(self, id_list: list):
361+
job_list = [{'id': elm} for elm in id_list]
362+
endpoint = "/api/v1/job/cancel"
363+
364+
payload = {'job_list': job_list, 'mode': 'archive'}
365+
366+
response = self.client.session.post(self.client.host + endpoint, json = payload)
367+
368+
self.client.handle_errors(response)
369+
370+
data = response.json()
371+
372+
if data["log"]["success"] == True:
373+
return True
374+
375+
return False
376+
351377
def get_by_id(
352378
self,
353379
id: int):

0 commit comments

Comments
 (0)