mirror of
https://github.com/MarekWo/mc-webui.git
synced 2026-03-28 17:42:45 +01:00
fix: Retry device name detection when bridge is not ready at startup
The background thread now retries with exponential backoff (5s→60s) instead of giving up after 3 attempts. Also accepts detected device name from bridge even when bridge health status is unhealthy. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
15
app/main.py
15
app/main.py
@@ -6,6 +6,7 @@ import logging
|
||||
import re
|
||||
import shlex
|
||||
import threading
|
||||
import time
|
||||
import requests
|
||||
from flask import Flask, request as flask_request
|
||||
from flask_socketio import SocketIO, emit
|
||||
@@ -88,11 +89,23 @@ def create_app():
|
||||
else:
|
||||
logger.info("Archive scheduler disabled")
|
||||
|
||||
# Fetch device name from bridge in background thread
|
||||
# Fetch device name from bridge in background thread (with retry)
|
||||
def init_device_name():
|
||||
device_name, source = fetch_device_name_from_bridge()
|
||||
runtime_config.set_device_name(device_name, source)
|
||||
|
||||
# If we got a fallback name, keep retrying in background
|
||||
retry_delay = 5
|
||||
max_delay = 60
|
||||
while source == "fallback":
|
||||
time.sleep(retry_delay)
|
||||
device_name, source = fetch_device_name_from_bridge()
|
||||
if source != "fallback":
|
||||
runtime_config.set_device_name(device_name, source)
|
||||
logger.info(f"Device name resolved after retry: {device_name}")
|
||||
break
|
||||
retry_delay = min(retry_delay * 2, max_delay)
|
||||
|
||||
threading.Thread(target=init_device_name, daemon=True).start()
|
||||
|
||||
logger.info(f"mc-webui started - device: {config.MC_DEVICE_NAME}")
|
||||
|
||||
@@ -996,7 +996,7 @@ def fetch_device_name_from_bridge(max_retries: int = 3, retry_delay: float = 2.0
|
||||
response = requests.get(bridge_health_url, timeout=5)
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
if data.get('status') == 'healthy':
|
||||
if data.get('status') == 'healthy' or data.get('device_name_source') == 'detected':
|
||||
device_name = data.get('device_name')
|
||||
source = data.get('device_name_source', 'unknown')
|
||||
if device_name:
|
||||
|
||||
Reference in New Issue
Block a user