Exits process when encountered by a database exception 69/7169/1
authorBenjamin Diaz <bdiaz@whitestack.com>
Fri, 25 Jan 2019 17:30:20 +0000 (14:30 -0300)
committerBenjamin Diaz <bdiaz@whitestack.com>
Fri, 1 Feb 2019 12:56:15 +0000 (09:56 -0300)
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 <bdiaz@whitestack.com>
osm_policy_module/core/agent.py

index f7cd679..205b98c 100644 (file)
@@ -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: ")