From c780bcee14e8d01f9deeeeb0e9483d5ce60b3350 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Mon, 14 Nov 2022 13:34:23 +0100 Subject: [PATCH] feat(alerts): changed logs feat(alerts): allow rollback on exception --- api/chalicelib/core/alerts_processor.py | 9 ++++----- ee/api/chalicelib/core/alerts_processor.py | 11 +++++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/api/chalicelib/core/alerts_processor.py b/api/chalicelib/core/alerts_processor.py index 4cf3fc507..f9604658b 100644 --- a/api/chalicelib/core/alerts_processor.py +++ b/api/chalicelib/core/alerts_processor.py @@ -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: diff --git a/ee/api/chalicelib/core/alerts_processor.py b/ee/api/chalicelib/core/alerts_processor.py index 1870c1f6c..d45d3c464 100644 --- a/ee/api/chalicelib/core/alerts_processor.py +++ b/ee/api/chalicelib/core/alerts_processor.py @@ -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