Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

stop jobs once all tasks are stopped #649

Merged
4 commits merged into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 14 additions & 0 deletions src/api-service/__app__/onefuzzlib/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ def init(self) -> None:
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)
Expand Down
5 changes: 5 additions & 0 deletions src/api-service/__app__/onefuzzlib/tasks/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,18 @@ def init(self) -> None:

def stopping(self) -> None:
# TODO: we need to 'unschedule' this task from the existing pools
from ..jobs import Job

logging.info("stopping task: %s:%s", self.job_id, self.task_id)
ProxyForward.remove_forward(self.task_id)
delete_queue(str(self.task_id), StorageType.corpus)
Node.stop_task(self.task_id)
self.set_state(TaskState.stopped, send=False)

job = Job.get(self.job_id)
if job:
job.stop_if_all_done()

@classmethod
def search_states(
cls, *, job_id: Optional[UUID] = None, states: Optional[List[TaskState]] = None
Expand Down