Adjust API level on swagger and set API doc expansion by default
[pti/o2.git] / o2ims / service / messagebus.py
index 0758529..297aa8f 100644 (file)
 
 # pylint: disable=broad-except, attribute-defined-outside-init
 from __future__ import annotations
-import logging
 from typing import Callable, Dict, List, Union, Type, TYPE_CHECKING
 from o2ims.domain import commands, events
 
 if TYPE_CHECKING:
     from . import unit_of_work
 
-logger = logging.getLogger(__name__)
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
 
 Message = Union[commands.Command, events.Event]
 
@@ -41,7 +41,9 @@ class MessageBus:
         self.queue = [message]
         while self.queue:
             message = self.queue.pop(0)
-            if isinstance(message, events.Event):
+            if not message:
+                continue
+            elif isinstance(message, events.Event):
                 self.handle_event(message)
             elif isinstance(message, commands.Command):
                 self.handle_command(message)
@@ -65,6 +67,6 @@ class MessageBus:
             handler = self.command_handlers[type(command)]
             handler(command)
             self.queue.extend(self.uow.collect_new_events())
-        except Exception:
+        except Exception as ex:
             logger.exception("Exception handling command %s", command)
-            raise
+            raise ex