Skip to content

Commit 3fdbb72

Browse files
committed
bring static handlers dicts across from messagebus
1 parent b9a0590 commit 3fdbb72

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
if TYPE_CHECKING:
@@ -92,3 +92,16 @@ def remove_allocation_from_read_model(
9292
dict(orderid=event.orderid, sku=event.sku)
9393
)
9494
uow.commit()
95+
96+
97+
EVENT_HANDLERS = {
98+
events.Allocated: [publish_allocated_event, add_allocation_to_read_model],
99+
events.Deallocated: [remove_allocation_from_read_model, reallocate],
100+
events.OutOfStock: [send_out_of_stock_notification],
101+
} # type: Dict[Type[events.Event], List[Callable]]
102+
103+
COMMAND_HANDLERS = {
104+
commands.Allocate: allocate,
105+
commands.CreateBatch: add_batch,
106+
commands.ChangeBatchQuantity: change_batch_quantity,
107+
} # 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)