Skip to content

Commit ac81443

Browse files
committed
use self.handlers for handle_event and handle_command [messagebus_handlers_change]
1 parent d26396e commit ac81443

File tree

1 file changed

+18
-28
lines changed

1 file changed

+18
-28
lines changed
Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# pylint: disable=broad-except
1+
# pylint: disable=broad-except, attribute-defined-outside-init
22
from __future__ import annotations
33
import logging
44
from typing import Callable, Dict, List, Union, Type, TYPE_CHECKING
@@ -34,32 +34,22 @@ def handle(self, message: Message):
3434
else:
3535
raise Exception(f"{message} was not an Event or Command")
3636

37-
38-
def handle_event(
39-
event: events.Event,
40-
queue: List[Message],
41-
uow: unit_of_work.AbstractUnitOfWork,
42-
):
43-
for handler in EVENT_HANDLERS[type(event)]:
37+
def handle_event(self, event: events.Event):
38+
for handler in self.event_handlers[type(event)]:
39+
try:
40+
logger.debug("handling event %s with handler %s", event, handler)
41+
handler(event)
42+
self.queue.extend(self.uow.collect_new_events())
43+
except Exception:
44+
logger.exception("Exception handling event %s", event)
45+
continue
46+
47+
def handle_command(self, command: commands.Command):
48+
logger.debug("handling command %s", command)
4449
try:
45-
logger.debug("handling event %s with handler %s", event, handler)
46-
handler(event, uow=uow)
47-
queue.extend(uow.collect_new_events())
50+
handler = self.command_handlers[type(command)]
51+
handler(command)
52+
self.queue.extend(self.uow.collect_new_events())
4853
except Exception:
49-
logger.exception("Exception handling event %s", event)
50-
continue
51-
52-
53-
def handle_command(
54-
command: commands.Command,
55-
queue: List[Message],
56-
uow: unit_of_work.AbstractUnitOfWork,
57-
):
58-
logger.debug("handling command %s", command)
59-
try:
60-
handler = COMMAND_HANDLERS[type(command)]
61-
handler(command, uow=uow)
62-
queue.extend(uow.collect_new_events())
63-
except Exception:
64-
logger.exception("Exception handling command %s", command)
65-
raise
54+
logger.exception("Exception handling command %s", command)
55+
raise

0 commit comments

Comments
 (0)