mirror of
https://github.com/MarekWo/mc-webui.git
synced 2026-07-06 01:41:07 +02: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:
+14
-1
@@ -6,6 +6,7 @@ import logging
|
|||||||
import re
|
import re
|
||||||
import shlex
|
import shlex
|
||||||
import threading
|
import threading
|
||||||
|
import time
|
||||||
import requests
|
import requests
|
||||||
from flask import Flask, request as flask_request
|
from flask import Flask, request as flask_request
|
||||||
from flask_socketio import SocketIO, emit
|
from flask_socketio import SocketIO, emit
|
||||||
@@ -88,11 +89,23 @@ def create_app():
|
|||||||
else:
|
else:
|
||||||
logger.info("Archive scheduler disabled")
|
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():
|
def init_device_name():
|
||||||
device_name, source = fetch_device_name_from_bridge()
|
device_name, source = fetch_device_name_from_bridge()
|
||||||
runtime_config.set_device_name(device_name, source)
|
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()
|
threading.Thread(target=init_device_name, daemon=True).start()
|
||||||
|
|
||||||
logger.info(f"mc-webui started - device: {config.MC_DEVICE_NAME}")
|
logger.info(f"mc-webui started - device: {config.MC_DEVICE_NAME}")
|
||||||
|
|||||||
+1
-1
@@ -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)
|
response = requests.get(bridge_health_url, timeout=5)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
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')
|
device_name = data.get('device_name')
|
||||||
source = data.get('device_name_source', 'unknown')
|
source = data.get('device_name_source', 'unknown')
|
||||||
if device_name:
|
if device_name:
|
||||||
|
|||||||
Reference in New Issue
Block a user