Skip to content

Add Job Output dirs attachment #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2022
Merged
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
33 changes: 32 additions & 1 deletion sdk/diffgram/job/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class Job():

valid_output_dir_actions = ['copy', 'move']
def __init__(self,
client,
job_dict = None):
Expand Down Expand Up @@ -137,6 +137,31 @@ def serialize(self):
'member_list_ids': self.member_list_ids,
'tag_list': self.tag_list
}
def attach_output_dir(self, dir: Directory, action = 'copy'):

if action not in self.valid_output_dir_actions:
raise ValueError(f'Invalid actions. Can only be {self.valid_output_dir_actions}')

data = {
'job_id': self.id,
'output_dir': str(dir.id),
'output_dir_action': action
}
endpoint = "/api/v1/project/{}/job/set-output-dir".format(self.client.project_string_id)
response = self.client.session.post(
self.client.host + endpoint,
json = data)

self.client.handle_errors(response)

data = response.json()

if data["log"]["success"] == True:
# TODO review better way to update fields
self.id = data["job"]["id"]

return self


def new(self,
name = None,
Expand All @@ -157,6 +182,8 @@ def new(self,
members_list_ids = [],
auto_launch = True,
tag_list = [],
output_dir = None,
output_dir_action = None
):
"""

Expand Down Expand Up @@ -227,6 +254,10 @@ def new(self,
if guide:
job.guide_update(guide = guide)

if output_dir and output_dir_action:
if output_dir_action not in self.valid_output_dir_actions:
raise ValueError(f'Invalid actions. Can only be {self.valid_output_dir_actions}')
job.attach_output_dir(dir = output_dir, action = output_dir_action)
if auto_launch:
endpoint_launch = "/api/v1/job/launch".format(self.client.project_string_id)
response = self.client.session.post(
Expand Down