Skip to content

Commit d4c63ab

Browse files
committed
subhandler for commands [handle_command]
1 parent 3b24b6c commit d4c63ab

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/allocation/service_layer/messagebus.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# pylint: disable=bare-except
1+
# pylint: disable=broad-except
22
from __future__ import annotations
33
import logging
44
from typing import List, Dict, Callable, Type, Union, TYPE_CHECKING
@@ -46,6 +46,22 @@ def handle_event(
4646
continue
4747

4848

49+
def handle_command(
50+
command: commands.Command,
51+
queue: List[Message],
52+
uow: unit_of_work.AbstractUnitOfWork,
53+
):
54+
logger.debug("handling command %s", command)
55+
try:
56+
handler = COMMAND_HANDLERS[type(command)]
57+
result = handler(command, uow=uow)
58+
queue.extend(uow.collect_new_events())
59+
return result
60+
except Exception:
61+
logger.exception("Exception handling command %s", command)
62+
raise
63+
64+
4965
HANDLERS = {
5066
events.BatchCreated: [handlers.add_batch],
5167
events.BatchQuantityChanged: [handlers.change_batch_quantity],

0 commit comments

Comments
 (0)