diff --git a/app/lib/redshift_database.py b/app/lib/redshift_database.py index f78c9a578487c89bdd88aa491bca2e064bc13e56..6c287520a91e557ca3acc31d0864da53f219be7d 100644 --- a/app/lib/redshift_database.py +++ b/app/lib/redshift_database.py @@ -38,19 +38,23 @@ class RedshiftWrapper(object): """ Execute a database call and handle the InterfaceError Returns the cursor that should be used to make future calls """ - try: - cursor.execute(sql, where_tuple) - except psycopg2.ProgrammingError as e: - self.current_app.logger.info( - 'ProgrammingError while executing redshift db call: {}'.format(e.message) - ) - self.db.rollback() - except psycopg2.InterfaceError as e: - self.current_app.logger.info( - 'InterfaceError while executing redshift db call: {}'.format(e.message) - ) - self.db = self.make_connection() - return self.get_cursor() + retry_counter = 0 + while retry_counter < 5: + retry_counter += 1 + try: + cursor.execute(sql, where_tuple) + break + except psycopg2.ProgrammingError as e: + self.current_app.logger.info( + 'ProgrammingError while executing redshift db call: {}'.format(e.message) + ) + self.db.rollback() + except (psycopg2.InterfaceError, psycopg2.OperationalError) as e: + self.current_app.logger.info( + 'Interface or Operational Error while executing redshift db call: {}'.format(e.message) + ) + self.db = self.make_connection() + cursor = self.get_cursor() return cursor