From fe68e98804b1f38fe2e0fb2b729c33c81889dce3 Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Mon, 24 Jun 2019 02:13:09 -0700 Subject: [PATCH] sheetsync: Fix a failure mode where we never recover from a DB conn failure Since we never got a new conn after failure, we would just keep erroring with "connection already closed" errors. --- sheetsync/sheetsync/main.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sheetsync/sheetsync/main.py b/sheetsync/sheetsync/main.py index 1553f7b..f51b27c 100644 --- a/sheetsync/sheetsync/main.py +++ b/sheetsync/sheetsync/main.py @@ -27,7 +27,7 @@ class SheetSync(object): def __init__(self, stop, dbmanager, sheets, sheet_id, worksheets, edit_url, bustime_start, allocate_ids=False): self.stop = stop - self.conn = dbmanager.get_conn() + self.dbmanager = dbmanager self.sheets = sheets self.sheet_id = sheet_id self.worksheets = worksheets @@ -90,6 +90,8 @@ class SheetSync(object): self.stop.wait(common.jitter(interval)) def run(self): + self.conn = self.dbmanager.get_conn() + while not self.stop.is_set(): try: @@ -109,6 +111,9 @@ class SheetSync(object): self.sync_row(worksheet, row_index, row, events.get(row['id'])) except Exception: logging.exception("Failed to sync") + # To ensure a fresh slate and clear any DB-related errors, get a new conn on error. + # This is heavy-handed but simple and effective. + self.conn = self.dbmanager.get_conn() self.wait(self.ERROR_RETRY_INTERVAL) else: logging.info("Successful sync")