feat: graceful shutdown and WAL cleanup
Some checks failed
CI / Backend Tests (push) Has been cancelled
CI / Lint (push) Has been cancelled
CI / Type Check (push) Has been cancelled
CI / Import Boundary (push) Has been cancelled
CI / OpenAPI Breaking Changes (push) Has been cancelled
CI / OpenAPI Baseline Commit (push) Has been cancelled
Some checks failed
CI / Backend Tests (push) Has been cancelled
CI / Lint (push) Has been cancelled
CI / Type Check (push) Has been cancelled
CI / Import Boundary (push) Has been cancelled
CI / OpenAPI Breaking Changes (push) Has been cancelled
CI / OpenAPI Baseline Commit (push) Has been cancelled
- Add stop_grace_period to backend container for graceful shutdown - Document WAL mode rationale and orphaned file cleanup in db.py - Handle database close errors gracefully in lifespan - Clean up orphaned WAL files during startup before opening DB - Reorder imports and fix formatting in startup.py
This commit was merged in pull request #4.
This commit is contained in:
@@ -274,7 +274,18 @@ CREATE INDEX IF NOT EXISTS idx_import_log_source_id_desc
|
||||
|
||||
|
||||
async def _configure_connection(db: aiosqlite.Connection) -> None:
|
||||
"""Apply hardening pragmas to a newly-opened SQLite connection."""
|
||||
"""Apply hardening pragmas to a newly-opened SQLite connection.
|
||||
|
||||
WAL mode is intentionally kept despite the risk of orphaned ``.wal``/``.shm``
|
||||
files after unclean shutdowns. The benefits for concurrent readers
|
||||
(readers do not block writers) outweigh the cleanup overhead, especially
|
||||
under load. BanGUI runs as a single worker, but multiple concurrent HTTP
|
||||
requests can still issue overlapping reads; DELETE mode would serialize
|
||||
those reads behind any write, degrading API performance.
|
||||
|
||||
Orphaned files are handled by :func:`_cleanup_wal_files`, which is called
|
||||
during startup before the database is opened.
|
||||
"""
|
||||
await db.execute("PRAGMA journal_mode=WAL;")
|
||||
await db.execute("PRAGMA foreign_keys=ON;")
|
||||
await db.execute("PRAGMA busy_timeout=5000;")
|
||||
|
||||
Reference in New Issue
Block a user