Skip to content

Commit fd79a8e

Browse files
committed
new handlers that take a uow [change_batch_new_handlers]
1 parent e17c944 commit fd79a8e

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/allocation/messagebus.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import List, Dict, Callable, Type
2-
from allocation import email, events
2+
from allocation import email, events, services, redis_pubsub
33

44

55
def handle(events_: List[events.Event]):
@@ -9,15 +9,31 @@ def handle(events_: List[events.Event]):
99
handler(event)
1010

1111

12-
def send_out_of_stock_notification(event: events.OutOfStock):
12+
def send_out_of_stock_notification(
13+
event: events.OutOfStock, uow: unit_of_work.AbstractUnitOfWork
14+
):
1315
email.send_mail(
1416
'stock@made.com',
1517
f'Out of stock for {event.sku}',
1618
)
1719

1820

21+
def reallocate(
22+
event: events.Deallocated, uow: unit_of_work.AbstractUnitOfWork
23+
):
24+
services.allocate(event.orderid, event.sku, event.qty, uow=uow)
25+
26+
27+
def publish_allocated_event(
28+
event: events.Allocated, uow: unit_of_work.AbstractUnitOfWork,
29+
):
30+
redis_pubsub.publish('line_allocated', event)
31+
32+
1933
HANDLERS = {
2034
events.OutOfStock: [send_out_of_stock_notification],
35+
events.Allocated: [publish_allocated_event],
36+
events.Deallocated: [reallocate],
2137

2238
} # type: Dict[Type[events.Event], List[Callable]]
2339

0 commit comments

Comments
 (0)