Skip to content

Commit 6fc7ca6

Browse files
committed
use self.handlers for handle_event and handle_command [messagebus_handlers_change]
1 parent e0385a4 commit 6fc7ca6

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

src/allocation/service_layer/messagebus.py

Lines changed: 19 additions & 27 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
@@ -36,31 +36,23 @@ def handle(self, message: Message):
3636
raise Exception(f'{message} was not an Event or Command')
3737

3838

39-
def handle_event(
40-
event: events.Event,
41-
queue: List[Message],
42-
uow: unit_of_work.AbstractUnitOfWork
43-
):
44-
for handler in EVENT_HANDLERS[type(event)]:
45-
try:
46-
logger.debug('handling event %s with handler %s', event, handler)
47-
handler(event, uow=uow)
48-
queue.extend(uow.collect_new_events())
49-
except Exception:
50-
logger.exception('Exception handling event %s', event)
51-
continue
39+
def handle_event(self, event: events.Event):
40+
for handler in self.event_handlers[type(event)]:
41+
try:
42+
logger.debug('handling event %s with handler %s', event, handler)
43+
handler(event)
44+
self.queue.extend(self.uow.collect_new_events())
45+
except Exception:
46+
logger.exception('Exception handling event %s', event)
47+
continue
5248

5349

54-
def handle_command(
55-
command: commands.Command,
56-
queue: List[Message],
57-
uow: unit_of_work.AbstractUnitOfWork
58-
):
59-
logger.debug('handling command %s', command)
60-
try:
61-
handler = COMMAND_HANDLERS[type(command)]
62-
handler(command, uow=uow)
63-
queue.extend(uow.collect_new_events())
64-
except Exception:
65-
logger.exception('Exception handling command %s', command)
66-
raise
50+
def handle_command(self, command: commands.Command):
51+
logger.debug('handling command %s', command)
52+
try:
53+
handler = self.command_handlers[type(command)]
54+
handler(command)
55+
self.queue.extend(self.uow.collect_new_events())
56+
except Exception:
57+
logger.exception('Exception handling command %s', command)
58+
raise

0 commit comments

Comments
 (0)