From a96898dfaf088ac15560d15a7dcaf982c671ac2f Mon Sep 17 00:00:00 2001 From: Benjamin Diaz Date: Fri, 25 Jan 2019 14:30:20 -0300 Subject: [PATCH] Exits process when encountered by a database exception Database errors could mean database node failure. In this cases, the process should exit so it could be automatically restarted (when handled by Docker Swarm, K8s, etc) so it can obtain a new DB connection to an alive node. Change-Id: I42a3954fe238a0445101eb71add79aaef4315c2e Signed-off-by: Benjamin Diaz --- osm_policy_module/core/agent.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/osm_policy_module/core/agent.py b/osm_policy_module/core/agent.py index f7cd679..205b98c 100644 --- a/osm_policy_module/core/agent.py +++ b/osm_policy_module/core/agent.py @@ -27,6 +27,7 @@ import json import logging from json import JSONDecodeError +import peewee import yaml from aiokafka import AIOKafkaConsumer @@ -77,6 +78,7 @@ class PolicyModuleAgent: await self._process_msg(msg.topic, msg.key, msg.value) finally: await consumer.stop() + log.critical("Exiting...") async def _process_msg(self, topic, key, msg): log.debug("_process_msg topic=%s key=%s msg=%s", topic, key, msg) @@ -97,6 +99,9 @@ class PolicyModuleAgent: await self._handle_alarm_notification(content) else: log.debug("Key %s is not in ALLOWED_KAFKA_KEYS", key) + except peewee.PeeweeException: + log.exception("Database error consuming message: ") + raise except Exception: log.exception("Error consuming message: ") -- 2.25.1