Skip to main content
Help improve PyPI by participating in a 5-minute user interface survey!

NTI Transactions Utility

Project Description

https://coveralls.io/repos/github/NextThought/nti.transactions/badge.svg?branch=master https://travis-ci.org/NextThought/nti.transactions.svg?branch=master

Extensions to the transaction package.

Transaction Manager

nti.transactions.transactions.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:

>>> class PyramidTransactionLoop(TransactionLoop):
...    def prep_for_retry(self, number, request):
...        request.make_body_seekable()
...    def describe_transaction(self, request):
...        return request.url

Data Managers

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.transactions 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.transactions import do
>>> do(print, args=("Committed"))

Caution!

See the documentation of this object for numerous warnings about side-effects and its interaction with the transaction machinery. Use it with care!

Changes

1.1.0 (2017-04-17)

  • Add a new ObjectDataManager that will attempt to execute after other ObjectDataManagers.

1.0.0 (2016-07-28)

  • 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

This version
History Node

1.1.0

History Node

1.0.0

History Node

0.0.0.dev0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
nti.transactions-1.1.0-py2.py3-none-any.whl (18.9 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Apr 17, 2017
nti.transactions-1.1.0.tar.gz (18.2 kB) Copy SHA256 hash SHA256 Source None Apr 17, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page