feat(alerts): changed logs
feat(alerts): allow rollback on exception
This commit is contained in:
parent
062aaf60d3
commit
c780bcee14
2 changed files with 9 additions and 11 deletions
|
|
@ -182,12 +182,12 @@ def process():
|
||||||
with pg_client.PostgresClient() as cur:
|
with pg_client.PostgresClient() as cur:
|
||||||
for alert in all_alerts:
|
for alert in all_alerts:
|
||||||
if can_check(alert):
|
if can_check(alert):
|
||||||
logging.info(f"Querying alertId:{alert['alertId']} name: {alert['name']}")
|
|
||||||
query, params = Build(alert)
|
query, params = Build(alert)
|
||||||
try:
|
try:
|
||||||
query = cur.mogrify(query, params)
|
query = cur.mogrify(query, params)
|
||||||
except Exception as e:
|
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)
|
logging.error(e)
|
||||||
continue
|
continue
|
||||||
logging.debug(alert)
|
logging.debug(alert)
|
||||||
|
|
@ -196,12 +196,11 @@ def process():
|
||||||
cur.execute(query)
|
cur.execute(query)
|
||||||
result = cur.fetchone()
|
result = cur.fetchone()
|
||||||
if result["valid"]:
|
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))
|
notifications.append(generate_notification(alert, result))
|
||||||
except Exception as e:
|
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)
|
logging.error(query)
|
||||||
print("------------")
|
|
||||||
logging.error(e)
|
logging.error(e)
|
||||||
cur = cur.recreate(rollback=True)
|
cur = cur.recreate(rollback=True)
|
||||||
if len(notifications) > 0:
|
if len(notifications) > 0:
|
||||||
|
|
|
||||||
|
|
@ -187,12 +187,12 @@ def process():
|
||||||
with pg_client.PostgresClient() as cur:
|
with pg_client.PostgresClient() as cur:
|
||||||
for alert in all_alerts:
|
for alert in all_alerts:
|
||||||
if can_check(alert):
|
if can_check(alert):
|
||||||
logging.info(f"Querying alertId:{alert['alertId']} name: {alert['name']}")
|
|
||||||
query, params = Build(alert)
|
query, params = Build(alert)
|
||||||
try:
|
try:
|
||||||
query = cur.mogrify(query, params)
|
query = cur.mogrify(query, params)
|
||||||
except Exception as e:
|
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)
|
logging.error(e)
|
||||||
continue
|
continue
|
||||||
logging.debug(alert)
|
logging.debug(alert)
|
||||||
|
|
@ -201,14 +201,13 @@ def process():
|
||||||
cur.execute(query)
|
cur.execute(query)
|
||||||
result = cur.fetchone()
|
result = cur.fetchone()
|
||||||
if result["valid"]:
|
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))
|
notifications.append(generate_notification(alert, result))
|
||||||
except Exception as e:
|
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)
|
logging.error(query)
|
||||||
print("------------")
|
|
||||||
logging.error(e)
|
logging.error(e)
|
||||||
cur = cur.recreate()
|
cur = cur.recreate(rollback=True)
|
||||||
if len(notifications) > 0:
|
if len(notifications) > 0:
|
||||||
cur.execute(
|
cur.execute(
|
||||||
cur.mogrify(f"""UPDATE public.Alerts
|
cur.mogrify(f"""UPDATE public.Alerts
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue