feat(alerts): changed logs

feat(alerts): allow rollback on exception
This commit is contained in:
Taha Yassine Kraiem 2022-11-14 13:34:23 +01:00
parent 062aaf60d3
commit c780bcee14
2 changed files with 9 additions and 11 deletions

View file

@ -182,12 +182,12 @@ def process():
with pg_client.PostgresClient() as cur:
for alert in all_alerts:
if can_check(alert):
logging.info(f"Querying alertId:{alert['alertId']} name: {alert['name']}")
query, params = Build(alert)
try:
query = cur.mogrify(query, params)
except Exception as e:
logging.error(f"!!!Error while building alert query for alertId:{alert['alertId']}")
logging.error(
f"!!!Error while building alert query for alertId:{alert['alertId']} name: {alert['name']}")
logging.error(e)
continue
logging.debug(alert)
@ -196,12 +196,11 @@ def process():
cur.execute(query)
result = cur.fetchone()
if result["valid"]:
logging.info("Valid alert, notifying users")
logging.info("Valid alert, notifying users, alertId:{alert['alertId']} name: {alert['name']}")
notifications.append(generate_notification(alert, result))
except Exception as e:
logging.error(f"!!!Error while running alert query for alertId:{alert['alertId']}")
logging.error(f"!!!Error while running alert query for alertId:{alert['alertId']} name: {alert['name']}")
logging.error(query)
print("------------")
logging.error(e)
cur = cur.recreate(rollback=True)
if len(notifications) > 0:

View file

@ -187,12 +187,12 @@ def process():
with pg_client.PostgresClient() as cur:
for alert in all_alerts:
if can_check(alert):
logging.info(f"Querying alertId:{alert['alertId']} name: {alert['name']}")
query, params = Build(alert)
try:
query = cur.mogrify(query, params)
except Exception as e:
logging.error(f"!!!Error while building alert query for alertId:{alert['alertId']}")
logging.error(
f"!!!Error while building alert query for alertId:{alert['alertId']} name: {alert['name']}")
logging.error(e)
continue
logging.debug(alert)
@ -201,14 +201,13 @@ def process():
cur.execute(query)
result = cur.fetchone()
if result["valid"]:
logging.info("Valid alert, notifying users")
logging.info("Valid alert, notifying users, alertId:{alert['alertId']} name: {alert['name']}")
notifications.append(generate_notification(alert, result))
except Exception as e:
logging.error(f"!!!Error while running alert query for alertId:{alert['alertId']}")
logging.error(f"!!!Error while running alert query for alertId:{alert['alertId']} name: {alert['name']}")
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