mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-15 03:18:07 +00:00
Unify Dashboard & Webhook events (#394)
This change unifies the previously adhoc SignalR events and Webhooks into a single event format.
This commit is contained in:
@ -8,8 +8,10 @@ from datetime import datetime, timedelta
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
from onefuzztypes.enums import JobState, TaskState
|
||||
from onefuzztypes.events import EventJobCreated, EventJobStopped
|
||||
from onefuzztypes.models import Job as BASE_JOB
|
||||
|
||||
from .events import send_event
|
||||
from .orm import MappingIntStrAny, ORMMixin, QueryFilter
|
||||
from .tasks.main import Task
|
||||
|
||||
@ -37,13 +39,6 @@ class Job(BASE_JOB, ORMMixin):
|
||||
def save_exclude(self) -> Optional[MappingIntStrAny]:
|
||||
return {"task_info": ...}
|
||||
|
||||
def event_include(self) -> Optional[MappingIntStrAny]:
|
||||
return {
|
||||
"job_id": ...,
|
||||
"state": ...,
|
||||
"error": ...,
|
||||
}
|
||||
|
||||
def telemetry_include(self) -> Optional[MappingIntStrAny]:
|
||||
return {
|
||||
"machine_id": ...,
|
||||
@ -70,6 +65,11 @@ class Job(BASE_JOB, ORMMixin):
|
||||
task.mark_stopping()
|
||||
else:
|
||||
self.state = JobState.stopped
|
||||
send_event(
|
||||
EventJobStopped(
|
||||
job_id=self.job_id, config=self.config, user_info=self.user_info
|
||||
)
|
||||
)
|
||||
self.save()
|
||||
|
||||
def on_start(self) -> None:
|
||||
@ -77,3 +77,14 @@ class Job(BASE_JOB, ORMMixin):
|
||||
if self.end_time is None:
|
||||
self.end_time = datetime.utcnow() + timedelta(hours=self.config.duration)
|
||||
self.save()
|
||||
|
||||
def save(self, new: bool = False, require_etag: bool = False) -> None:
|
||||
created = self.etag is None
|
||||
super().save(new=new, require_etag=require_etag)
|
||||
|
||||
if created:
|
||||
send_event(
|
||||
EventJobCreated(
|
||||
job_id=self.job_id, config=self.config, user_info=self.user_info
|
||||
)
|
||||
)
|
||||
|
Reference in New Issue
Block a user