added gunicorn and updated to the last version of server monitorizare
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
Database configuration and connection management
|
||||
"""
|
||||
import os
|
||||
from sqlalchemy import create_engine, MetaData
|
||||
import sqlite3
|
||||
from sqlalchemy import create_engine, MetaData, event
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from contextlib import contextmanager
|
||||
from app.models import Base
|
||||
@@ -38,7 +39,19 @@ class DatabaseConfig:
|
||||
pool_pre_ping=True,
|
||||
connect_args={"check_same_thread": False} # For SQLite
|
||||
)
|
||||
|
||||
|
||||
# Enable WAL mode + sane concurrency settings on each SQLite connection.
|
||||
# WAL lets readers and writers operate concurrently, preventing
|
||||
# 'database is locked' errors under multi-worker Gunicorn.
|
||||
@event.listens_for(self.engine, "connect")
|
||||
def _set_sqlite_pragma(dbapi_connection, connection_record):
|
||||
if isinstance(dbapi_connection, sqlite3.Connection):
|
||||
cursor = dbapi_connection.cursor()
|
||||
cursor.execute("PRAGMA journal_mode=WAL")
|
||||
cursor.execute("PRAGMA busy_timeout=5000")
|
||||
cursor.execute("PRAGMA synchronous=NORMAL")
|
||||
cursor.close()
|
||||
|
||||
# Create session factory
|
||||
self.Session = sessionmaker(bind=self.engine)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user