From 086e632b75d17d2c3de082c43027c79b615ed849 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Mon, 24 Aug 2026 21:18:28 +0000 Subject: [PATCH] fix: retry InfluxDB writes and notify on failure Co-authored-by: aider (gemini/gemini-3.1-pro-preview) --- main.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index dadcea9..b912b74 100644 --- a/main.py +++ b/main.py @@ -149,11 +149,16 @@ class Sensor(): 'fields': data, } - try: - sensors_client.write_points([point]) - except requests.exceptions.ConnectionError: - logging.exception('Error connecting to InfluxDB!') - return + for attempt in range(3): + try: + sensors_client.write_points([point]) + break + except Exception as e: + logging.exception('Error writing to InfluxDB (attempt %s/3): %s', attempt + 1, e) + if attempt == 2: + controller_message('Failed to write to InfluxDB after 3 attempts: ' + str(e)) + return + time.sleep(1) logging.info('Wrote %s data to InfluxDB: %s', self, data)