From: Benjamin Diaz Date: Fri, 25 Jan 2019 17:30:20 +0000 (-0300) Subject: Exits process when encountered by a database exception X-Git-Tag: v6.0.0~15 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=a96898dfaf088ac15560d15a7dcaf982c671ac2f;p=osm%2FPOL.git 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 --- 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: ")