mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-17 12:28:07 +00:00
send EventTaskFailed and EventTaskStopped once the task is stopped (#651)
As is, these events are sent once the task enters the state `stopping`. However, the tasks can still be running on the VMs which can be confusing.
This commit is contained in:
@ -132,7 +132,7 @@ class Task(BASE_TASK, ORMMixin):
|
|||||||
ProxyForward.remove_forward(self.task_id)
|
ProxyForward.remove_forward(self.task_id)
|
||||||
delete_queue(str(self.task_id), StorageType.corpus)
|
delete_queue(str(self.task_id), StorageType.corpus)
|
||||||
Node.stop_task(self.task_id)
|
Node.stop_task(self.task_id)
|
||||||
self.set_state(TaskState.stopped, send=False)
|
self.set_state(TaskState.stopped)
|
||||||
|
|
||||||
job = Job.get(self.job_id)
|
job = Job.get(self.job_id)
|
||||||
if job:
|
if job:
|
||||||
@ -188,43 +188,25 @@ class Task(BASE_TASK, ORMMixin):
|
|||||||
return pool_tasks
|
return pool_tasks
|
||||||
|
|
||||||
def mark_stopping(self) -> None:
|
def mark_stopping(self) -> None:
|
||||||
if self.state in [TaskState.stopped, TaskState.stopping]:
|
if self.state in TaskState.shutting_down():
|
||||||
logging.debug(
|
logging.debug(
|
||||||
"ignoring post-task stop calls to stop %s:%s", self.job_id, self.task_id
|
"ignoring post-task stop calls to stop %s:%s", self.job_id, self.task_id
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
self.set_state(TaskState.stopping, send=False)
|
self.set_state(TaskState.stopping)
|
||||||
send_event(
|
|
||||||
EventTaskStopped(
|
|
||||||
job_id=self.job_id,
|
|
||||||
task_id=self.task_id,
|
|
||||||
user_info=self.user_info,
|
|
||||||
config=self.config,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def mark_failed(
|
def mark_failed(
|
||||||
self, error: Error, tasks_in_job: Optional[List["Task"]] = None
|
self, error: Error, tasks_in_job: Optional[List["Task"]] = None
|
||||||
) -> None:
|
) -> None:
|
||||||
if self.state in [TaskState.stopped, TaskState.stopping]:
|
if self.state in TaskState.shutting_down():
|
||||||
logging.debug(
|
logging.debug(
|
||||||
"ignoring post-task stop failures for %s:%s", self.job_id, self.task_id
|
"ignoring post-task stop failures for %s:%s", self.job_id, self.task_id
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
self.error = error
|
self.error = error
|
||||||
self.set_state(TaskState.stopping, send=False)
|
self.set_state(TaskState.stopping)
|
||||||
|
|
||||||
send_event(
|
|
||||||
EventTaskFailed(
|
|
||||||
job_id=self.job_id,
|
|
||||||
task_id=self.task_id,
|
|
||||||
error=error,
|
|
||||||
user_info=self.user_info,
|
|
||||||
config=self.config,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
self.mark_dependants_failed(tasks_in_job=tasks_in_job)
|
self.mark_dependants_failed(tasks_in_job=tasks_in_job)
|
||||||
|
|
||||||
@ -320,7 +302,7 @@ class Task(BASE_TASK, ORMMixin):
|
|||||||
def key_fields(cls) -> Tuple[str, str]:
|
def key_fields(cls) -> Tuple[str, str]:
|
||||||
return ("job_id", "task_id")
|
return ("job_id", "task_id")
|
||||||
|
|
||||||
def set_state(self, state: TaskState, send: bool = True) -> None:
|
def set_state(self, state: TaskState) -> None:
|
||||||
if self.state == state:
|
if self.state == state:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -330,6 +312,27 @@ class Task(BASE_TASK, ORMMixin):
|
|||||||
|
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
if self.state == TaskState.stopped:
|
||||||
|
if self.error:
|
||||||
|
send_event(
|
||||||
|
EventTaskFailed(
|
||||||
|
job_id=self.job_id,
|
||||||
|
task_id=self.task_id,
|
||||||
|
error=self.error,
|
||||||
|
user_info=self.user_info,
|
||||||
|
config=self.config,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
send_event(
|
||||||
|
EventTaskStopped(
|
||||||
|
job_id=self.job_id,
|
||||||
|
task_id=self.task_id,
|
||||||
|
user_info=self.user_info,
|
||||||
|
config=self.config,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
send_event(
|
send_event(
|
||||||
EventTaskStateUpdated(
|
EventTaskStateUpdated(
|
||||||
job_id=self.job_id,
|
job_id=self.job_id,
|
||||||
|
Reference in New Issue
Block a user