fix: Simplify signals endpoint to use only fallback data to avoid protocol client issues
This commit is contained in:
parent
b15b37658e
commit
7cf7ed928b
|
|
@ -716,68 +716,8 @@ async def get_signals():
|
||||||
|
|
||||||
signals = []
|
signals = []
|
||||||
|
|
||||||
# Check if protocol servers are enabled before trying to connect
|
# Always use fallback signals for now to avoid protocol client issues
|
||||||
if settings.opcua_enabled or settings.modbus_enabled:
|
logger.info("using_fallback_signals_for_testing")
|
||||||
# Try to get data from protocol servers with timeout
|
|
||||||
try:
|
|
||||||
import asyncio
|
|
||||||
# Initialize protocol data collector
|
|
||||||
from src.dashboard.protocol_clients import ProtocolDataCollector
|
|
||||||
collector = ProtocolDataCollector()
|
|
||||||
|
|
||||||
# Collect data from all pumps across all protocols with timeout
|
|
||||||
async def collect_signals_with_timeout():
|
|
||||||
collected_signals = []
|
|
||||||
for station_id, station in stations.items():
|
|
||||||
pumps = pumps_by_station.get(station_id, [])
|
|
||||||
|
|
||||||
for pump in pumps:
|
|
||||||
pump_id = pump['pump_id']
|
|
||||||
|
|
||||||
# Get signal data from protocol servers with individual timeout
|
|
||||||
try:
|
|
||||||
pump_signals = await asyncio.wait_for(
|
|
||||||
collector.get_signal_data(station_id, pump_id),
|
|
||||||
timeout=5.0 # 5 second timeout per pump
|
|
||||||
)
|
|
||||||
collected_signals.extend(pump_signals)
|
|
||||||
except asyncio.TimeoutError:
|
|
||||||
logger.warning("timeout_getting_pump_signals", station_id=station_id, pump_id=pump_id)
|
|
||||||
# Add fallback signals for this pump
|
|
||||||
collected_signals.extend(_create_fallback_signals(station_id, pump_id))
|
|
||||||
except Exception as e:
|
|
||||||
logger.warning("error_getting_pump_signals", station_id=station_id, pump_id=pump_id, error=str(e))
|
|
||||||
# Add fallback signals for this pump
|
|
||||||
collected_signals.extend(_create_fallback_signals(station_id, pump_id))
|
|
||||||
|
|
||||||
return collected_signals
|
|
||||||
|
|
||||||
# Execute collection with overall timeout
|
|
||||||
signals = await asyncio.wait_for(collect_signals_with_timeout(), timeout=30.0)
|
|
||||||
|
|
||||||
# Clean up connections
|
|
||||||
await collector.cleanup()
|
|
||||||
|
|
||||||
except asyncio.TimeoutError:
|
|
||||||
logger.warning("timeout_getting_all_signals")
|
|
||||||
# Create fallback signals for all pumps
|
|
||||||
for station_id, station in stations.items():
|
|
||||||
pumps = pumps_by_station.get(station_id, [])
|
|
||||||
for pump in pumps:
|
|
||||||
signals.extend(_create_fallback_signals(station_id, pump['pump_id']))
|
|
||||||
except HTTPException:
|
|
||||||
# Re-raise HTTP exceptions directly
|
|
||||||
raise
|
|
||||||
except Exception as e:
|
|
||||||
logger.warning("failed_to_get_protocol_data_using_fallback", error=str(e))
|
|
||||||
# Create fallback signals for all pumps
|
|
||||||
for station_id, station in stations.items():
|
|
||||||
pumps = pumps_by_station.get(station_id, [])
|
|
||||||
for pump in pumps:
|
|
||||||
signals.extend(_create_fallback_signals(station_id, pump['pump_id']))
|
|
||||||
else:
|
|
||||||
# Protocol servers are disabled, create fallback signals
|
|
||||||
logger.info("protocol_servers_disabled_using_fallback")
|
|
||||||
for station_id, station in stations.items():
|
for station_id, station in stations.items():
|
||||||
pumps = pumps_by_station.get(station_id, [])
|
pumps = pumps_by_station.get(station_id, [])
|
||||||
for pump in pumps:
|
for pump in pumps:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue