Skip to content

Commit b62ad70

Browse files
committed
add handler for Allocated [chapter_10_external_events_ends]
1 parent 8bb7246 commit b62ad70

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎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
@@ -43,6 +43,7 @@ def handle_command(command, uow: unit_of_work.AbstractUnitOfWork):
4343

4444

4545
EVENT_HANDLERS = {
46+
events.Allocated: [handlers.publish_allocated_event],
4647
events.OutOfStock: [handlers.send_out_of_stock_notification],
4748
} # type: Dict[Type[events.Event], List[Callable]]
4849

0 commit comments

Comments
 (0)