fastrag.serve.cleanup#
Expired-row cleanup, callable from an external scheduler.
Functions
|
Delete expired sessions and chats. |
Classes
|
How many expired rows were deleted. |
- class fastrag.serve.cleanup.CleanupReport(sessions, chats)[source]#
Bases:
objectHow many expired rows were deleted.
- async fastrag.serve.cleanup.cleanup_expired(engine, *, target='all', batch_size=1000)[source]#
Delete expired sessions and chats.
Deleting a session cascades to its chats and messages; chats are swept separately because a chat can go idle while its session stays active.
Deletes in bounded batches — one transaction per batch — for the same reason a single unbounded
DELETEwould be wrong: cascading through chats and messages in one very large transaction would hold locks and bloat WAL for as long as it ran. Sessions are swept before chats, mirroring the cascade.This function carries the deletion logic but never runs it itself — nothing in the request path calls it. It is meant to be invoked on a daily cadence by an external scheduler (cron, a Kubernetes
CronJob, …); a short script under cron calls it.- Parameters:
engine (AsyncEngine) – The async engine to run the deletes on. The caller typically passes a
PostgresChatStore’sengine. The SQL targets the plain table names (sessions/chats) on the engine’s search path — a store pointed at a non-default schema requires a schema-qualified variant (see this task’s result file).target (str) –
"sessions","chats", or"all".batch_size (int) – Rows deleted per transaction.
- Returns:
A
CleanupReportof rows deleted per table.- Return type: