Skip to content

Commit 81de780

Browse files
committed
add handler for Allocated [chapter_10_external_events_ends]
1 parent dc20429 commit 81de780

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎src/allocation/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 import commands, events, email, exceptions, model
3+
from allocation import commands, events, email, exceptions, model, redis_pubsub
44
from allocation.model import OrderLine
55
if TYPE_CHECKING:
66
from allocation import unit_of_work
@@ -42,10 +42,18 @@ def change_batch_quantity(
4242
uow.commit()
4343

4444

45+
#pylint: disable=unused-argument
46+
4547
def send_out_of_stock_notification(
4648
event: events.OutOfStock, uow: unit_of_work.AbstractUnitOfWork,
4749
):
4850
email.send(
4951
'stock@made.com',
5052
f'Out of stock for {event.sku}',
5153
)
54+
55+
56+
def publish_allocated_event(
57+
event: events.Allocated, uow: unit_of_work.AbstractUnitOfWork,
58+
):
59+
redis_pubsub.publish('line_allocated', event)

‎src/allocation/messagebus.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def handle_command(command, uow: unit_of_work.AbstractUnitOfWork):
3939

4040

4141
EVENT_HANDLERS = {
42+
events.Allocated: [handlers.publish_allocated_event],
4243
events.OutOfStock: [handlers.send_out_of_stock_notification],
4344
} # type: Dict[Type[events.Event], List[Callable]]
4445

0 commit comments

Comments
 (0)