Moodle PHP Documentation 4.1
Moodle 4.1.11 (Build: 20240610) (c8c84b4af18)
MongoDB\Operation\WithTransaction Class Reference

Public Member Functions

 __construct (callable $callback, array $transactionOptions=[])
 
 execute (Session $session)
 Execute the operation in the given session.
 

Constructor & Destructor Documentation

◆ __construct()

MongoDB\Operation\WithTransaction::__construct ( callable $callback,
array $transactionOptions = [] )
See also
Session\startTransaction for supported transaction options
Parameters
callable$callbackA callback that will be invoked within the transaction
array$transactionOptionsAdditional options that are passed to Session\startTransaction

Member Function Documentation

◆ execute()

MongoDB\Operation\WithTransaction::execute ( Session $session)

Execute the operation in the given session.

This helper takes care of retrying the commit operation or the entire transaction if an error occurs.

If the commit fails because of an UnknownTransactionCommitResult error, the commit is retried without re-invoking the callback. If the commit fails because of a TransientTransactionError, the entire transaction will be retried. In this case, the callback will be invoked again. It is important that the logic inside the callback is idempotent.

In case of failures, the commit or transaction are retried until 120 seconds from the initial call have elapsed. After that, no retries will happen and the helper will throw the last exception received from the driver.

See also
Client\startSession
Parameters
Session$sessionA session object as retrieved by Client\startSession
Exceptions
RuntimeExceptionfor driver errors while committing the transaction
Exceptionfor any other errors, including those thrown in the callback

The documentation for this class was generated from the following file: