Лабораторная 4 - Костылев - БПИ2303 - На 5 #132
@@ -28,11 +28,12 @@ class CommandBus:
|
|||||||
handler = self._handlers.get(type(command))
|
handler = self._handlers.get(type(command))
|
||||||
if handler is None:
|
if handler is None:
|
||||||
raise LookupError(f"нет обработчика для команды {type(command).__name__}")
|
raise LookupError(f"нет обработчика для команды {type(command).__name__}")
|
||||||
result = await handler(command)
|
try:
|
||||||
|
return await handler(command)
|
||||||
|
finally:
|
||||||
events = self._uow.collect_new_events()
|
events = self._uow.collect_new_events()
|
||||||
if events:
|
if events:
|
||||||
await self._publisher.publish(events)
|
await self._publisher.publish(events)
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
class EventBus:
|
class EventBus:
|
||||||
|
|||||||
@@ -95,11 +95,12 @@ class PostgresUnitOfWork:
|
|||||||
self._transaction = connection.transaction()
|
self._transaction = connection.transaction()
|
||||||
await self._transaction.start()
|
await self._transaction.start()
|
||||||
self._committed = False
|
self._committed = False
|
||||||
|
mark = len(self._events)
|
||||||
try:
|
try:
|
||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
if not self._committed:
|
if not self._committed:
|
||||||
self._events.clear()
|
del self._events[mark:]
|
||||||
await self._transaction.rollback()
|
await self._transaction.rollback()
|
||||||
self.seen.clear()
|
self.seen.clear()
|
||||||
self._connection = None
|
self._connection = None
|
||||||
|
|||||||
Reference in New Issue
Block a user