feat: app lifespan starts/stops EmbeddingWorker (T97.3)
This commit is contained in:
+15
@@ -16,6 +16,7 @@ from chat.db.migrate import apply_migrations
|
||||
from chat.eventlog.log import read_events
|
||||
from chat.eventlog.projector import apply_event
|
||||
from chat.services.background import BackgroundWorker
|
||||
from chat.services.embedding_worker import EmbeddingWorker
|
||||
from chat.services.snapshot import latest_snapshot_path, restore_from_snapshot
|
||||
|
||||
# Trigger handler registration:
|
||||
@@ -85,9 +86,23 @@ async def lifespan(app: FastAPI):
|
||||
await worker.start()
|
||||
app.state.background_worker = worker
|
||||
|
||||
# T97: separate worker for the async embedding pass. Each
|
||||
# ``memory_written`` enqueues an EmbeddingJob; the worker drains the
|
||||
# queue, calls ``generate_embedding``, and emits ``embedding_indexed``.
|
||||
# Phase 4's pseudo-embedding path is local so the worker doesn't need
|
||||
# an LLM client; we still pass one so the Phase 4.5 swap to a real
|
||||
# model is a one-line change.
|
||||
embedding_worker = EmbeddingWorker(
|
||||
conn_factory=lambda: open_db(settings.db_path),
|
||||
client=_factory(),
|
||||
)
|
||||
await embedding_worker.start()
|
||||
app.state.embedding_worker = embedding_worker
|
||||
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
await embedding_worker.stop()
|
||||
await worker.stop()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user