11from typing import List , Dict , Callable , Type
2- from allocation import email , events
2+ from allocation import email , events , services , redis_pubsub
33
44
55def 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+
1933HANDLERS = {
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