unit_of_work

class mersal.unit_of_work.UnitOfWorkConfig

Bases: object

Configuration for unit of work feature.

__init__(uow_factory: Callable[[MessageContext], Awaitable[UnitOfWorkT]], commit_action: Callable[[MessageContext, UnitOfWorkT], Awaitable], rollback_action: Callable[[MessageContext, UnitOfWorkT], Awaitable], close_action: Callable[[MessageContext, UnitOfWorkT], Awaitable], commit_with_transaction: bool = False) None
close_action: Callable[[MessageContext, UnitOfWorkT], Awaitable]

Action to run on close and cleanup the unit of work object.

Can be used to close database sessions for example.

commit_action: Callable[[MessageContext, UnitOfWorkT], Awaitable]

Action to run on commit.

commit_with_transaction: bool = False

Commit before or with the TransactionContext commit.

When True, the uow commit is part of the TransactionContext commit actions. This is required for the outbox and idempotency features to work.

rollback_action: Callable[[MessageContext, UnitOfWorkT], Awaitable]

Action to run on callback.

uow_factory: Callable[[MessageContext], Awaitable[UnitOfWorkT]]

Callback to create the unit of work object.

The callback is given MessageContext as an argument. This allows for creating custom unit of work objects depending on the message contents and/or headers.