Fix: Fixed database is locked error when enabling WAL in SQLite
This commit is contained in:
@@ -293,6 +293,8 @@ def on_connect(client, userdata, flags, reason_code, properties=None):
|
||||
|
||||
def on_disconnect(client, userdata, disconnect_flags, reason_code, properties=None):
|
||||
logger.warning(f"⚠️ Disconnessione dal broker MQTT! Codice: {reason_code}")
|
||||
logger.error("Forzo il riavvio del processo per ripristinare la rete in modo pulito...")
|
||||
os._exit(1) # Uccide lo script immediatamente (Systemd lo farà risorgere)
|
||||
|
||||
def on_message(client, userdata, msg):
|
||||
global boot_recovered, current_status, cfg
|
||||
|
||||
@@ -13,7 +13,7 @@ from logging.handlers import RotatingFileHandler
|
||||
# --- CONFIGURAZIONE LOGGING ---
|
||||
logging.basicConfig(
|
||||
handlers=[
|
||||
RotatingFileHandler('/opt/web-control/fleet_console.log', maxBytes=2000000, backupCount=3),
|
||||
RotatingFileHandler('/opt/web-control/fleet_console.log', maxBytes=10000000, backupCount=3),
|
||||
logging.StreamHandler()
|
||||
],
|
||||
level=logging.INFO,
|
||||
@@ -21,6 +21,8 @@ logging.basicConfig(
|
||||
datefmt='%Y-%m-%d %H:%M:%S'
|
||||
)
|
||||
logger = logging.getLogger("FleetHub")
|
||||
# Silenzia lo spam delle richieste HTTP (GET /api/states 200 OK)
|
||||
logging.getLogger('werkzeug').setLevel(logging.ERROR)
|
||||
|
||||
# --- PERCORSI ---
|
||||
DB_PATH = '/opt/web-control/monitor.db'
|
||||
@@ -33,6 +35,9 @@ CLIENTS_PATH = '/opt/web-control/clients.json'
|
||||
def init_db():
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
c = conn.cursor()
|
||||
|
||||
c.execute('PRAGMA journal_mode=WAL;') # <-- MAGIA: Abilita letture/scritture simultanee!
|
||||
|
||||
c.execute('''CREATE TABLE IF NOT EXISTS radio_logs
|
||||
(id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp DATETIME, client_id TEXT,
|
||||
source_id TEXT, target TEXT, slot INTEGER, duration REAL, ber REAL, loss REAL)''')
|
||||
@@ -158,7 +163,7 @@ def on_message(client, userdata, msg):
|
||||
device_configs[cid_conf] = {}
|
||||
try:
|
||||
device_configs[cid_conf][svc_name] = json.loads(payload)
|
||||
logger.info(f"Configurazione salvata per {cid_conf} -> {svc_name}")
|
||||
logger.debug(f"Configurazione salvata per {cid_conf} -> {svc_name}")
|
||||
except Exception as e:
|
||||
logger.error(f"Errore parsing config JSON: {e}")
|
||||
|
||||
@@ -313,7 +318,7 @@ def get_clients():
|
||||
|
||||
@app.route('/api/logs')
|
||||
def get_logs():
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
conn = sqlite3.connect(DB_PATH, timeout=10)
|
||||
c = conn.cursor()
|
||||
c.execute("SELECT timestamp, client_id, protocol, source_id, target, slot, duration, ber FROM radio_logs ORDER BY id DESC LIMIT 60")
|
||||
logs = c.fetchall()
|
||||
|
||||
Reference in New Issue
Block a user