cd src
pdm run uvicorn main:app --workers 8
curl -X POST "http://localhost:8000/items/" -H "accept: application/json" -H "Content-Type: application/json" -d '{"name":"item_post_route"}'
We can see that if we open 2 terminals, and run:
pdm run tests/post.py test_111
then 1 ou 2 sec after:
pdm run tests/post.py test_222
We have this result (which means that the UoW are isolated in each thread)
--- START ---
Just register in UoW: name='item_post_route_test_111'
add 'item_post_route_test_111' to []
heavy work in progress...
--- START ---
Just register in UoW: name='item_post_route_test_222'
add 'item_post_route_test_222' to []
heavy work in progress...
Just register in UoW: name='another_inner_item'
add 'another_inner_item' to ['item_post_route_test_111']
Just register in UoW: name='inner_item'
add 'inner_item' to ['item_post_route_test_111', 'another_inner_item']
--- END ---
--- EXIT ---
FROM UoW:
Model SAVED in DB: name='item_post_route_test_111'
FROM UoW:
Model SAVED in DB: name='another_inner_item'
FROM UoW:
Model SAVED in DB: name='inner_item'
INFO: 127.0.0.1:63077 - "POST /items/ HTTP/1.1" 200 OK
Just register in UoW: name='another_inner_item'
add 'another_inner_item' to ['item_post_route_test_222']
Just register in UoW: name='inner_item'
add 'inner_item' to ['item_post_route_test_222', 'another_inner_item']
--- END ---
--- EXIT ---
FROM UoW:
Model SAVED in DB: name='item_post_route_test_222'
FROM UoW:
Model SAVED in DB: name='another_inner_item'
FROM UoW:
Model SAVED in DB: name='inner_item'
INFO: 127.0.0.1:63094 - "POST /items/ HTTP/1.1" 200 OK
We can also uncomment the raise NotImplementedError()
in UseCase
and see that no save is done if there is an error in the middle on the UoW