Skip to content

Commit 3812f16

Browse files
committed
messagebus has uow, manages queue [handle_has_uow_and_queue]
1 parent 541ab52 commit 3812f16

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/allocation/service_layer/messagebus.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44
from . import handlers
55

66
if TYPE_CHECKING:
7-
from allocation.service_layer import unit_of_work
7+
from . import unit_of_work
88

99

1010
def handle(
1111
event: events.Event,
1212
uow: unit_of_work.AbstractUnitOfWork,
1313
):
14-
for handler in HANDLERS[type(event)]:
15-
handler(event, uow=uow)
14+
queue = [event]
15+
while queue:
16+
event = queue.pop(0)
17+
for handler in HANDLERS[type(event)]:
18+
handler(event, uow=uow)
19+
queue.extend(uow.collect_new_events())
1620

1721

1822
HANDLERS = {

0 commit comments

Comments
 (0)