Skip to content

Commit 71ba7ab

Browse files
committed
add retrying and quiet failure on random value insert
1 parent bf227c7 commit 71ba7ab

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/charm.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,17 @@ def _write_random_value(self) -> str:
205205
"""Write a random value to the database."""
206206
if not self._database_config:
207207
return ""
208-
209-
with MySQLConnector(self._database_config) as cursor:
210-
self._create_test_table(cursor)
211-
random_value = self._generate_random_values(10)
212-
self._insert_test_data(cursor, random_value)
208+
random_value = ""
209+
try:
210+
for attempt in Retrying(stop=stop_after_delay(60), wait=wait_fixed(5)):
211+
with attempt:
212+
with MySQLConnector(self._database_config) as cursor:
213+
self._create_test_table(cursor)
214+
random_value = self._generate_random_values(10)
215+
self._insert_test_data(cursor, random_value)
216+
except RetryError:
217+
logger.exception("Unable to write to the database")
218+
return random_value
213219

214220
logger.info("Wrote random_value")
215221

0 commit comments

Comments
 (0)