Harden score endpoint with resilient fallback and sqlite race/lock handling
This commit is contained in:
parent
198bbd89ab
commit
e67d8ad0f5
3 changed files with 80 additions and 14 deletions
|
|
@ -6,15 +6,17 @@ DB_PATH = BASE_DIR / "data" / "staysense.db"
|
|||
|
||||
|
||||
def get_conn() -> sqlite3.Connection:
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
conn = sqlite3.connect(DB_PATH, timeout=10)
|
||||
conn.row_factory = sqlite3.Row
|
||||
conn.execute("PRAGMA foreign_keys = ON")
|
||||
conn.execute("PRAGMA busy_timeout = 10000")
|
||||
return conn
|
||||
|
||||
|
||||
def init_db() -> None:
|
||||
DB_PATH.parent.mkdir(parents=True, exist_ok=True)
|
||||
with get_conn() as conn:
|
||||
conn.execute("PRAGMA journal_mode = WAL")
|
||||
conn.executescript(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS spot (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue