fix: improve logging clarity and ensure data delivery in AgentMQTTAdapter
This commit is contained in:
@@ -39,12 +39,13 @@ class AgentMQTTAdapter(AgentGateway):
|
||||
agent_data = AgentData.model_validate_json(payload, strict=True)
|
||||
# Process the received data (you can call a use case here if needed)
|
||||
processed_data = process_agent_data(agent_data)
|
||||
# Store the agent_data in the database (you can send it to the data processing module)
|
||||
if processed_data is not None:
|
||||
if not self.hub_gateway.save_data(processed_data):
|
||||
logging.error("Hub is not available")
|
||||
# Attempt to send processed data to the Hub gateway
|
||||
if self.hub_gateway.save_data(processed_data):
|
||||
# Log successful transmission as INFO level
|
||||
logging.info("Processed data successfully forwarded to the Hub.")
|
||||
else:
|
||||
logging.info("Road is fine, no data sent to hub.")
|
||||
# Log Hub unavailability or transmission failure as ERROR level
|
||||
logging.error("Failed to send data: Hub gateway is unavailable.")
|
||||
except Exception as e:
|
||||
logging.info(f"Error processing MQTT message: {e}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user