|
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
|
@@ -36,31 +36,23 @@ def handle(self, message: Message):
|
36 | 36 | raise Exception(f'{message} was not an Event or Command')
|
37 | 37 |
|
38 | 38 |
|
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 |
52 | 48 |
|
53 | 49 |
|
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