Skip to content

Commit 0b3f74a

Browse files
committed
add handler for Allocated [chapter_11_external_events_ends]
1 parent e34840f commit 0b3f74a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/allocation/service_layer/handlers.py

Lines changed: 9 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
if TYPE_CHECKING:
@@ -47,10 +47,18 @@ def change_batch_quantity(
4747
uow.commit()
4848

4949

50+
#pylint: disable=unused-argument
51+
5052
def send_out_of_stock_notification(
5153
event: events.OutOfStock, uow: unit_of_work.AbstractUnitOfWork,
5254
):
5355
email.send(
5456
'stock@made.com',
5557
f'Out of stock for {event.sku}',
5658
)
59+
60+
61+
def publish_allocated_event(
62+
event: events.Allocated, uow: unit_of_work.AbstractUnitOfWork,
63+
):
64+
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
@@ -60,6 +60,7 @@ def handle_command(
6060

6161

6262
EVENT_HANDLERS = {
63+
events.Allocated: [handlers.publish_allocated_event],
6364
events.OutOfStock: [handlers.send_out_of_stock_notification],
6465
} # type: Dict[Type[events.Event], List[Callable]]
6566

0 commit comments

Comments
 (0)