|
1 | | -# pylint: disable=broad-except |
| 1 | +# pylint: disable=broad-except, attribute-defined-outside-init |
2 | 2 | from __future__ import annotations |
3 | 3 | import logging |
4 | 4 | from typing import Callable, Dict, List, Union, Type, TYPE_CHECKING |
@@ -34,32 +34,22 @@ def handle(self, message: Message): |
34 | 34 | else: |
35 | 35 | raise Exception(f"{message} was not an Event or Command") |
36 | 36 |
|
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) |
44 | 49 | 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()) |
48 | 53 | 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