Skip to content

Commit

Permalink
feat:add dpcloudserver and openapi kill job (#357)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
xiaoyeqiannian and pre-commit-ci[bot] committed Aug 10, 2023
1 parent 1721e52 commit 587a077
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
13 changes: 10 additions & 3 deletions dpdispatcher/dp_cloud_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,16 @@ def map_dp_job_state(status):
return JobStatus.unknown
return map_dict[status]

# def check_finish_tag(self, job):
# job_tag_finished = job.job_hash + '_job_tag_finished'
# return self.context.check_file_exists(job_tag_finished)
def kill(self, job):
"""Kill the job.
Parameters
----------
job : Job
job
"""
job_id = job.job_id
self.api.kill(job_id)


DpCloudServer = Bohrium
Expand Down
13 changes: 13 additions & 0 deletions dpdispatcher/dpcloudserver/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,16 @@ def get_job_result_url(self, job_id):
except ValueError as e:
dlog.error(e, stack_info=ENABLE_STACK)
return None

def kill(self, job_id):
try:
if not job_id:
return None
if "job_group_id" in job_id:
ids = job_id.split(":job_group_id:")
job_id, _ = int(ids[0]), int(ids[1])
ret = self.post(f"/brm/v1/job/kill/{job_id}", {})
return ret
except ValueError as e:
dlog.error(e, stack_info=ENABLE_STACK)
return None
11 changes: 11 additions & 0 deletions dpdispatcher/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ def map_dp_job_state(status):
return JobStatus.unknown
return map_dict[status]

def kill(self, job):
"""Kill the job.
Parameters
----------
job : Job
job
"""
job_id = job.job_id
self.job.kill(job_id)

# def check_finish_tag(self, job):
# job_tag_finished = job.job_hash + '_job_tag_finished'
# return self.context.check_file_exists(job_tag_finished)
2 changes: 1 addition & 1 deletion dpdispatcher/openapi_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def upload(self, submission):
result = None
dlog.info("checking all job has been uploaded")
for job in submission.belonging_jobs:
if job.job_state == JobStatus.unsubmitted:
if job.job_state in (JobStatus.unsubmitted, JobStatus.terminated):
job_to_be_uploaded.append(job)
if len(job_to_be_uploaded) == 0:
dlog.info("all job has been uploaded, continue")
Expand Down

0 comments on commit 587a077

Please sign in to comment.