feat(chalice): pg_client allow rollback on recreation

This commit is contained in:
Taha Yassine Kraiem 2022-11-10 20:58:13 +01:00
parent 67cdd2cfd9
commit 3296c7a891
2 changed files with 7 additions and 2 deletions

View file

@ -203,7 +203,7 @@ def process():
logging.error(query)
print("------------")
logging.error(e)
cur = cur.recreate()
cur = cur.recreate(rollback=True)
if len(notifications) > 0:
cur.execute(
cur.mogrify(f"""UPDATE public.Alerts

View file

@ -136,7 +136,12 @@ class PostgresClient:
and not self.unlimited_query:
postgreSQL_pool.putconn(self.connection)
def recreate_cursor(self):
def recreate_cursor(self, rollback=False):
if rollback:
try:
self.connection.rollback()
except Exception as error:
logging.error("Error while rollbacking connection for recreation", error)
try:
self.cursor.close()
except Exception as error: