42 lines
970 B
Python
42 lines
970 B
Python
"""
|
|
Detection pipeline event helpers.
|
|
|
|
Non-generated runtime code for pushing SSE events.
|
|
The event payload types are in sse_contract.py (generated by modelgen).
|
|
"""
|
|
|
|
from pydantic import BaseModel
|
|
|
|
from core.events import push_event
|
|
|
|
DETECT_EVENTS_PREFIX = "detect_events"
|
|
|
|
# SSE event type names
|
|
EVENT_GRAPH_UPDATE = "graph_update"
|
|
EVENT_STATS_UPDATE = "stats_update"
|
|
EVENT_FRAME_UPDATE = "frame_update"
|
|
EVENT_DETECTION = "detection"
|
|
EVENT_LOG = "log"
|
|
EVENT_JOB_COMPLETE = "job_complete"
|
|
|
|
ALL_EVENT_TYPES = [
|
|
EVENT_GRAPH_UPDATE,
|
|
EVENT_STATS_UPDATE,
|
|
EVENT_FRAME_UPDATE,
|
|
EVENT_DETECTION,
|
|
EVENT_LOG,
|
|
EVENT_JOB_COMPLETE,
|
|
]
|
|
|
|
TERMINAL_EVENTS = [EVENT_JOB_COMPLETE]
|
|
|
|
|
|
def push_detect_event(job_id: str, event_type: str, data: BaseModel) -> None:
|
|
"""Push a typed detection event to Redis."""
|
|
push_event(
|
|
job_id=job_id,
|
|
event_type=event_type,
|
|
data=data.model_dump(mode="json"),
|
|
prefix=DETECT_EVENTS_PREFIX,
|
|
)
|