Fix event cleanup

This commit is contained in:
Nicolas Mowen 2024-10-10 10:48:24 -06:00
parent 9928592266
commit d5eab6c794
3 changed files with 15 additions and 6 deletions

View File

@ -117,7 +117,7 @@ class EmbeddingsContext:
query_embedding = serialize(
self.requestor.send_data(
EmbeddingsRequestEnum.embed_thumbnail.value,
{"id": query.id, "thumbnail": query.thumbnail},
{"id": str(query.id), "thumbnail": str(query.thumbnail)},
)
)
else:

View File

@ -77,6 +77,10 @@ class EmbeddingMaintainer(threading.Thread):
"""Process embeddings requests"""
def handle_request(topic: str, data: str) -> str:
logger.debug(
f"Handling embeddings request of type {topic} with data {data}"
)
try:
if topic == EmbeddingsRequestEnum.embed_description.value:
return serialize(
@ -112,6 +116,7 @@ class EmbeddingMaintainer(threading.Thread):
if not camera or source_type != EventTypeEnum.tracked_object:
return
logger.debug(f"Processing object update of type {source_type} on {camera}")
camera_config = self.config.cameras[camera]
if data["id"] not in self.tracked_events:
self.tracked_events[data["id"]] = []
@ -141,6 +146,9 @@ class EmbeddingMaintainer(threading.Thread):
break
event_id, camera, updated_db = ended
logger.debug(
f"Processing finalized event for {camera} which updated the db: {updated_db}"
)
camera_config = self.config.cameras[camera]
if updated_db:
@ -234,6 +242,8 @@ class EmbeddingMaintainer(threading.Thread):
if topic is None:
return
logger.debug(f"Handling event metadata for id {event_id} and source {source}")
if event_id:
self.handle_regenerate_description(event_id, source)

View File

@ -8,10 +8,9 @@ from enum import Enum
from multiprocessing.synchronize import Event as MpEvent
from pathlib import Path
from playhouse.sqliteq import SqliteQueueDatabase
from frigate.config import FrigateConfig
from frigate.const import CLIPS_DIR
from frigate.db.sqlitevecq import SqliteVecQueueDatabase
from frigate.embeddings.embeddings import Embeddings
from frigate.models import Event, Timeline
@ -25,7 +24,7 @@ class EventCleanupType(str, Enum):
class EventCleanup(threading.Thread):
def __init__(
self, config: FrigateConfig, stop_event: MpEvent, db: SqliteQueueDatabase
self, config: FrigateConfig, stop_event: MpEvent, db: SqliteVecQueueDatabase
):
super().__init__(name="event_cleanup")
self.config = config
@ -234,8 +233,8 @@ class EventCleanup(threading.Thread):
Event.delete().where(Event.id << chunk).execute()
if self.config.semantic_search.enabled:
self.embeddings.delete_description(chunk)
self.embeddings.delete_thumbnail(chunk)
self.db.delete_embeddings_description(chunk)
self.db.delete_embeddings_thumbnail(chunk)
logger.debug(f"Deleted {len(events_to_delete)} embeddings")
logger.info("Exiting event cleanup...")