Лабораторная 4 - Костылев - БПИ2303 - На 5 #132

Closed
akostylev2303 wants to merge 77 commits from akostylev2303/mtusi2026lab4:solution/bpi2303-kostylev into main
2 changed files with 8 additions and 6 deletions
Showing only changes of commit 70a0c6065e - Show all commits
@@ -28,11 +28,12 @@ class CommandBus:
handler = self._handlers.get(type(command))
if handler is None:
raise LookupError(f"нет обработчика для команды {type(command).__name__}")
result = await handler(command)
events = self._uow.collect_new_events()
if events:
await self._publisher.publish(events)
return result
try:
return await handler(command)
finally:
events = self._uow.collect_new_events()
if events:
await self._publisher.publish(events)
class EventBus:
@@ -95,11 +95,12 @@ class PostgresUnitOfWork:
self._transaction = connection.transaction()
await self._transaction.start()
self._committed = False
mark = len(self._events)
try:
yield
finally:
if not self._committed:
self._events.clear()
del self._events[mark:]
await self._transaction.rollback()
self.seen.clear()
self._connection = None