Skip to content

Commit 867c070

Browse files
committed
add handler for Allocated [chapter_11_external_events_ends]
1 parent 904af48 commit 867c070

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/allocation/service_layer/handlers.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22
from typing import TYPE_CHECKING
3-
from allocation.adapters import email
3+
from allocation.adapters import email, redis_eventpublisher
44
from allocation.domain import commands, events, model
55
from allocation.domain.model import OrderLine
66

@@ -49,6 +49,9 @@ def change_batch_quantity(
4949
uow.commit()
5050

5151

52+
# pylint: disable=unused-argument
53+
54+
5255
def send_out_of_stock_notification(
5356
event: events.OutOfStock,
5457
uow: unit_of_work.AbstractUnitOfWork,
@@ -57,3 +60,10 @@ def send_out_of_stock_notification(
5760
"stock@made.com",
5861
f"Out of stock for {event.sku}",
5962
)
63+
64+
65+
def publish_allocated_event(
66+
event: events.Allocated,
67+
uow: unit_of_work.AbstractUnitOfWork,
68+
):
69+
redis_eventpublisher.publish("line_allocated", event)

src/allocation/service_layer/messagebus.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def handle_command(
6363

6464

6565
EVENT_HANDLERS = {
66+
events.Allocated: [handlers.publish_allocated_event],
6667
events.OutOfStock: [handlers.send_out_of_stock_notification],
6768
} # type: Dict[Type[events.Event], List[Callable]]
6869

0 commit comments

Comments
 (0)