stop jobs once all tasks are stopped (#649)

Fixed #643
This commit is contained in:
bmc-msft
2021-03-09 15:09:18 -05:00
committed by GitHub
parent f26838452b
commit b4ceb263e0
2 changed files with 19 additions and 0 deletions

View File

@ -85,6 +85,20 @@ class Job(BASE_JOB, ORMMixin):
self.state = JobState.enabled
self.save()
def stop_if_all_done(self) -> None:
not_stopped = [
task
for task in Task.search(query={"job_id": [self.job_id]})
if task.state != TaskState.stopped
]
if not_stopped:
return
logging.info(
JOB_LOG_PREFIX + "stopping job as all tasks are stopped: %s", self.job_id
)
self.stopping()
def stopping(self) -> None:
self.state = JobState.stopping
logging.info(JOB_LOG_PREFIX + "stopping: %s", self.job_id)