Skip to content

Commit 423f1fb

Browse files
committed
bring static handlers dicts across from messagebus
1 parent 66c478c commit 423f1fb

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

src/allocation/service_layer/handlers.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# pylint: disable=unused-argument
22
from __future__ import annotations
33
from dataclasses import asdict
4-
from typing import Callable, TYPE_CHECKING
4+
from typing import List, Dict, Callable, Type, TYPE_CHECKING
55
from allocation.domain import commands, events, model
66
from allocation.domain.model import OrderLine
77

@@ -104,3 +104,16 @@ def remove_allocation_from_read_model(
104104
dict(orderid=event.orderid, sku=event.sku),
105105
)
106106
uow.commit()
107+
108+
109+
EVENT_HANDLERS = {
110+
events.Allocated: [publish_allocated_event, add_allocation_to_read_model],
111+
events.Deallocated: [remove_allocation_from_read_model, reallocate],
112+
events.OutOfStock: [send_out_of_stock_notification],
113+
} # type: Dict[Type[events.Event], List[Callable]]
114+
115+
COMMAND_HANDLERS = {
116+
commands.Allocate: allocate,
117+
commands.CreateBatch: add_batch,
118+
commands.ChangeBatchQuantity: change_batch_quantity,
119+
} # type: Dict[Type[commands.Command], Callable]

src/allocation/service_layer/messagebus.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# pylint: disable=broad-except
22
from __future__ import annotations
33
import logging
4-
from typing import List, Dict, Callable, Type, Union, TYPE_CHECKING
4+
from typing import Union, TYPE_CHECKING
55
from allocation.domain import commands, events
66
from . import handlers
77

@@ -53,22 +53,3 @@ def handle_command(
5353
except Exception:
5454
logger.exception("Exception handling command %s", command)
5555
raise
56-
57-
58-
EVENT_HANDLERS = {
59-
events.Allocated: [
60-
handlers.publish_allocated_event,
61-
handlers.add_allocation_to_read_model,
62-
],
63-
events.Deallocated: [
64-
handlers.remove_allocation_from_read_model,
65-
handlers.reallocate,
66-
],
67-
events.OutOfStock: [handlers.send_out_of_stock_notification],
68-
} # type: Dict[Type[events.Event], List[Callable]]
69-
70-
COMMAND_HANDLERS = {
71-
commands.Allocate: handlers.allocate,
72-
commands.CreateBatch: handlers.add_batch,
73-
commands.ChangeBatchQuantity: handlers.change_batch_quantity,
74-
} # type: Dict[Type[commands.Command], Callable]

0 commit comments

Comments
 (0)