NTI Transactions Utility
Extensions to the transaction package.
nti.transactions.loop.TransactionsLoop is a retryable transaction manager. It is conceptually similar to the attempts context manager provided by the transaction package itself, but much more powerful and extensible via subclasses. Features include:
- Configurable commit vetos.
- Extensible tests for which exceptions should be retried.
- The ability to abort the transaction and bypass a potentially expensive commit when there are expected to be no side-effects.
- Sleeping between retries.
- Extensive logging and timing.
The TransactionLoop can be used as-is, or it can be subclassed for customization. For use in a Pyramid tween, for example, a minimal subclass might look like this (see nti.transactions.pyramid_tween for a full-featured tween):
>>> class PyramidTransactionLoop(TransactionLoop): ... def prep_for_retry(self, number, request): ... request.make_body_seekable() ... def describe_transaction(self, request): ... return request.url
A few data managers are provided for convenience.
The first data manager is used to put an object in a queue (something with the full and put_nowait methods) when a transaction succeeds. If the queue is full, then the transaction will not be allowed to commit:
>>> from nti.transactions.queue import put_nowait >>> put_nowait(queue, object)
This is a special case of the ObjectDataManager, which will call one method with any arguments when a transaction commits. It can be configured to vote on whether the transaction should be allowed to commit. or not. This is useful for, say, putting an item in a Redis queue when the transaction is successful. It can be constructed directly, but the do function is a shorthand way of joining one to the current transaction:
>>> from nti.transactions.manager import do >>> do(print, args=("Committed"))
See the documentation of this object for numerous warnings about side-effects and its interaction with the transaction machinery. Use it with care!
- Require at least version 3.0 of the transaction package.
- Drop dependency on the dm.transaction.aborthook package. That functionality is now natively provided in transaction 3.0.
- Add support for Python 3.8.
- Refactor internal implementation details. Instead of importing everything from nti.transactions.transactions, more specific modules are used to group objects by function. The old imports continue to work. In 4.0 they will generate a deprecation warning and in 5.0 they will be removed.
- Add a Pyramid tween to manage transactions and transaction retries. Various settings can be configured as Pyramid deployment settings (e.g., in the ini file).
- Make the transaction loop increase the time it sleeps between retries following the random binary exponential backoff algorithm used by Ethernet.
- Reduce the default number of attempts to 4 (one attempt and 3 retries). See issue 35.
- Make the transaction loop emit more metrics. See issue 31.
- Make commit logging now always happen at least at the debug level, escalating to warning for long commits. It also includes the number of retries taken and the amount of time spent sleeping. See issue 32.
- Make the transaction loop emit events (using zope.event) at certain parts of the transaction lifecycle. See issue 33.
- Make TransactionLoop place its transaction manager in explicit mode. This can be faster and is easier to reason about, but forbids the called handler from manually calling begin(), abort() or commit(). See issue 20.
- Move transaction.begin() out of the block of code that is retried. Previously, an error there would probably be raised anyway and not retried, unless a subclass had made customizations.
- Add setUp and tearDown methods to TransactionLoop to give subclasses a place to hook into the inners of the transaction loop. This is particularly helpful if they need to do something after the transaction manager has been put in explicit mode. See issue 22.
- Fix compatibility with perfmetrics 3.0: drop from __future__ import unicode_literals.
- Use the new public isRetryableError in transaction 2.2. The interface for this package is unchanged, but a major version bump of a dependency necessitates a major bump here. See issue 12.
- Test support for Python 3.7; remove test support for Python 3.4.
- TransactionLoop is more careful to not keep traceback objects around, especially on Python 2.
- When the TransactionLoop raises a CommitFailedError from a TypeError, it preserves the original message.
- Test support for Python 3.6.
- Add a new ObjectDataManager that will attempt to execute after other ObjectDataManagers.
- Add support for Python 3.
- Eliminate ZODB dependency. Instead of raising a ZODB.POSException.StorageError for unexpected TypeErrors during commit, the new class nti.transactions.interfaces.CommitFailedError is raised.
- Introduce a new subclass of TransactionError, AbortFailedError that is raised when an abort fails due to a system error.
Release history Release notifications
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size nti.transactions-4.0.0-py2.py3-none-any.whl (36.2 kB)||File type Wheel||Python version py2.py3||Upload date||Hashes View hashes|
|Filename, size nti.transactions-4.0.0.tar.gz (40.2 kB)||File type Source||Python version None||Upload date||Hashes View hashes|
Hashes for nti.transactions-4.0.0-py2.py3-none-any.whl