File tree Expand file tree Collapse file tree 2 files changed +27
-6
lines changed
src/allocation/service_layer Expand file tree Collapse file tree 2 files changed +27
-6
lines changed Original file line number Diff line number Diff line change 1+ from typing import List , Dict , Callable , Type
2+ from allocation .adapters import email
3+ from allocation .domain import events
4+
5+
6+ def handle (event : events .Event ):
7+ for handler in HANDLERS [type (event )]:
8+ handler (event )
9+
10+
11+ def send_out_of_stock_notification (event : events .OutOfStock ):
12+ email .send_mail (
13+ "stock@made.com" ,
14+ f"Out of stock for { event .sku } " ,
15+ )
16+
17+
18+ HANDLERS = {
19+ events .OutOfStock : [send_out_of_stock_notification ],
20+ } # type: Dict[Type[events.Event], List[Callable]]
Original file line number Diff line number Diff line change 11from __future__ import annotations
2- from typing import Optional
2+ from typing import Optional , TYPE_CHECKING
33from datetime import date
44
5- from allocation .adapters import email
65from allocation .domain import model
76from allocation .domain .model import OrderLine
8- from allocation .service_layer import unit_of_work
7+ from . import messagebus
8+
9+ if TYPE_CHECKING :
10+ from . import unit_of_work
911
1012
1113class InvalidSku (Exception ):
@@ -38,6 +40,5 @@ def allocate(
3840 batchref = product .allocate (line )
3941 uow .commit ()
4042 return batchref
41- except model .OutOfStock :
42- email .send_mail ("stock@made.com" , f"Out of stock for { line .sku } " )
43- raise
43+ finally :
44+ messagebus .handle (product .events )
You can’t perform that action at this time.
0 commit comments