nti.transactions


Namenti.transactions JSON
Version 4.3.0 PyPI version JSON
download
home_pagehttps://github.com/OpenNTI/nti.transactions
SummaryNTI Transactions Utility
upload_time2023-05-05 21:09:47
maintainer
docs_urlNone
authorJason Madden
requires_python
licenseApache
keywords zodb transaction
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            ==================
 nti.transactions
==================


.. _transaction: https://pypi.python.org/pypi/transaction

.. image:: https://coveralls.io/repos/github/NextThought/nti.transactions/badge.svg?branch=master
	:target: https://coveralls.io/github/NextThought/nti.transactions?branch=master

.. image:: https://github.com/NextThought/nti.transactions/workflows/tests/badge.svg
   :target: https://github.com/NextThought/nti.transactions/actions?query=workflow%3Atests

.. image:: https://readthedocs.org/projects/ntitransactions/badge/?version=latest
   :target: https://ntitransactions.readthedocs.io/en/latest/?badge=latest
   :alt: Documentation Status

Extensions to the `transaction`_ package.



Transaction Management
======================

``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

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.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"))

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

.. _attempts: http://zodb.readthedocs.io/en/latest/transactions.html#retrying-transactions
.. _data managers: http://zodb.readthedocs.io/en/latest/transactions.html#data-managers

=========
 Changes
=========

4.3.0 (2023-05-05)
==================

- Add support for Python 3.10 and 3.11.


4.2.1 (2021-05-25)
==================

- When aborting a transaction due to an exception, log the exception
  instead of just the exception type (twice). Exception messages can
  be very helpful in understanding exactly what went wrong and
  possibly how to fix it for transient errors (e.g., a
  ``ZODB.POSException.ConflictError`` includes the object ID and
  class, which can be used to reduce the conflicts). This makes the
  logging slightly more expensive (when enabled). See `PR 58
  <https://github.com/NextThought/nti.transactions/pull/58>`_.


4.2.0 (2021-02-11)
==================

- Add support for Python 3.9.
- Move CI from Travis CI to Github Actions.
- When the Pyramid tween retries, any volatile attributes (those
  beginning with ``_v_``) in the request dictionary are deleted. This
  is inspired by ``persistent`` and meant to facilitate safe caching.
  When compared to events sent by the transaction loop, there is no
  specified order. See `issue 54 <https://github.com/NextThought/nti.transactions/issues/54>`_.
- Fix various event classes not properly specifying the interface they
  implement. For example, ``WillFirstAttempt`` now properly implements
  ``IWillFirstAttempt``, and ``WilLRetryAttempt`` now properly
  implements ``IWillRetryAttempt``. See `issue 52
  <https://github.com/NextThought/nti.transactions/issues/52>`_.
- Add ``IWillLastAttempt`` as a subclass of ``IWillRetryAttempt`` and
  the last event emitted.
- The Pyramid tween now emits ``IWillRetryAttemptWithRequest``, et al,
  to provide simple access to the request object.

4.1.0 (2020-07-22)
==================

- Add logging to the pyramid tween transaction factory to show the
  settings that are in use.
- Add ``TransactionLoop.side_effect_free_log_level``, and change the
  default value to DEBUG. It is useful to set this to ERROR or higher
  in tests.
- Add ``TransactionLoop.side_effect_free_resource_limit``.


4.0.1 (2020-07-18)
==================

- Add missing dependency on zope.event.
- Fix raising ``AlreadyInTransaction`` error on the second and
  subsequent calls to a loop when a transaction synchronizer raises an
  error on the first call. See `issue 49
  <https://github.com/NextThought/nti.transactions/issues/49>`_.

4.0.0 (2019-12-13)
==================

- 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.


3.1.1 (2019-12-10)
==================

- Fix logging of long duration commits. See `issue 44
  <https://github.com/NextThought/nti.transactions/issues/44>`_.

- Add logging and a metric
  (``transaction.side_effect_free_violation``) for transactions that
  claim to have no side effects, but which actually result in joined
  resource managers. This can indicate unnecessarily throwing away
  work. See `issue 45 <https://github.com/NextThought/nti.transactions/issues/45>`_.


3.1.0 (2019-11-29)
==================

- 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
  <https://en.wikipedia.org/wiki/Exponential_backoff>`_ used by Ethernet.

- Reduce the default number of attempts to 4 (one attempt and 3
  retries). See `issue 35 <https://github.com/NextThought/nti.transactions/issues/35>`_.

- Make the transaction loop emit more metrics. See `issue 31
  <https://github.com/NextThought/nti.transactions/issues/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 <https://github.com/NextThought/nti.transactions/issues/32>`_.

- Make the transaction loop emit events (using ``zope.event``) at certain parts of the
  transaction lifecycle. See `issue 33 <https://github.com/NextThought/nti.transactions/issues/33>`_.

3.0.0 (2019-09-06)
==================

- 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
  <https://github.com/NextThought/nti.transactions/issues/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
  <https://github.com/NextThought/nti.transactions/issues/22>`_.

2.0.1 (2019-09-03)
==================

- Fix compatibility with perfmetrics 3.0: drop ``from __future__
  import unicode_literals``.


2.0.0 (2018-07-20)
==================

- 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
  <https://github.com/NextThought/nti.transactions/issues/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.

1.1.1 (2018-07-19)
==================

- When the ``TransactionLoop`` raises a ``CommitFailedError`` from a
  ``TypeError``, it preserves the original message.

- Test support for Python 3.6.

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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/OpenNTI/nti.transactions",
    "name": "nti.transactions",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "ZODB transaction",
    "author": "Jason Madden",
    "author_email": "jason@nextthought.com",
    "download_url": "https://files.pythonhosted.org/packages/37/42/28d9a6b708bb798a07168f932bb03564625d526c3b663dd64f82c27ee7e2/nti.transactions-4.3.0.tar.gz",
    "platform": null,
    "description": "==================\n nti.transactions\n==================\n\n\n.. _transaction: https://pypi.python.org/pypi/transaction\n\n.. image:: https://coveralls.io/repos/github/NextThought/nti.transactions/badge.svg?branch=master\n\t:target: https://coveralls.io/github/NextThought/nti.transactions?branch=master\n\n.. image:: https://github.com/NextThought/nti.transactions/workflows/tests/badge.svg\n   :target: https://github.com/NextThought/nti.transactions/actions?query=workflow%3Atests\n\n.. image:: https://readthedocs.org/projects/ntitransactions/badge/?version=latest\n   :target: https://ntitransactions.readthedocs.io/en/latest/?badge=latest\n   :alt: Documentation Status\n\nExtensions to the `transaction`_ package.\n\n\n\nTransaction Management\n======================\n\n``nti.transactions.loop.TransactionsLoop`` is a retryable\ntransaction manager. It is conceptually similar to the `attempts`_\ncontext manager provided by the transaction package itself, but much\nmore powerful and extensible via subclasses. Features include:\n\n- Configurable commit vetos.\n- Extensible tests for which exceptions should be retried.\n- The ability to abort the transaction and bypass a potentially\n  expensive commit when there are expected to be no side-effects.\n- Sleeping between retries.\n- Extensive logging and timing.\n\nThe TransactionLoop can be used as-is, or it can be subclassed for\ncustomization. For use in a Pyramid tween, for example, a minimal\nsubclass might look like this (see ``nti.transactions.pyramid_tween``\nfor a full-featured tween)::\n\n  >>> class PyramidTransactionLoop(TransactionLoop):\n  ...    def prep_for_retry(self, number, request):\n  ...        request.make_body_seekable()\n  ...    def describe_transaction(self, request):\n  ...        return request.url\n\nData Managers\n=============\n\nA few `data managers`_ are provided for convenience.\n\nThe first data manager is used to put an object in a ``queue``\n(something with the ``full`` and ``put_nowait`` methods) when a\ntransaction succeeds. If the queue is full, then the transaction will\nnot be allowed to commit::\n\n  >>> from nti.transactions.queue import put_nowait\n  >>> put_nowait(queue, object)\n\nThis is a special case of the ``ObjectDataManager``, which will call\none method with any arguments when a transaction commits. It can be\nconfigured to vote on whether the transaction should be allowed to commit.\nor not. This is useful for, say, putting an item in a Redis queue when\nthe transaction is successful. It can be constructed directly, but the\n``do`` function is a shorthand way of joining one to the current\ntransaction::\n\n  >>> from nti.transactions.manager import do\n  >>> do(print, args=(\"Committed\"))\n\n.. caution:: See the documentation of this object for numerous\n\t     warnings about side-effects and its interaction with the\n\t     transaction machinery. Use it with care!\n\n.. _attempts: http://zodb.readthedocs.io/en/latest/transactions.html#retrying-transactions\n.. _data managers: http://zodb.readthedocs.io/en/latest/transactions.html#data-managers\n\n=========\n Changes\n=========\n\n4.3.0 (2023-05-05)\n==================\n\n- Add support for Python 3.10 and 3.11.\n\n\n4.2.1 (2021-05-25)\n==================\n\n- When aborting a transaction due to an exception, log the exception\n  instead of just the exception type (twice). Exception messages can\n  be very helpful in understanding exactly what went wrong and\n  possibly how to fix it for transient errors (e.g., a\n  ``ZODB.POSException.ConflictError`` includes the object ID and\n  class, which can be used to reduce the conflicts). This makes the\n  logging slightly more expensive (when enabled). See `PR 58\n  <https://github.com/NextThought/nti.transactions/pull/58>`_.\n\n\n4.2.0 (2021-02-11)\n==================\n\n- Add support for Python 3.9.\n- Move CI from Travis CI to Github Actions.\n- When the Pyramid tween retries, any volatile attributes (those\n  beginning with ``_v_``) in the request dictionary are deleted. This\n  is inspired by ``persistent`` and meant to facilitate safe caching.\n  When compared to events sent by the transaction loop, there is no\n  specified order. See `issue 54 <https://github.com/NextThought/nti.transactions/issues/54>`_.\n- Fix various event classes not properly specifying the interface they\n  implement. For example, ``WillFirstAttempt`` now properly implements\n  ``IWillFirstAttempt``, and ``WilLRetryAttempt`` now properly\n  implements ``IWillRetryAttempt``. See `issue 52\n  <https://github.com/NextThought/nti.transactions/issues/52>`_.\n- Add ``IWillLastAttempt`` as a subclass of ``IWillRetryAttempt`` and\n  the last event emitted.\n- The Pyramid tween now emits ``IWillRetryAttemptWithRequest``, et al,\n  to provide simple access to the request object.\n\n4.1.0 (2020-07-22)\n==================\n\n- Add logging to the pyramid tween transaction factory to show the\n  settings that are in use.\n- Add ``TransactionLoop.side_effect_free_log_level``, and change the\n  default value to DEBUG. It is useful to set this to ERROR or higher\n  in tests.\n- Add ``TransactionLoop.side_effect_free_resource_limit``.\n\n\n4.0.1 (2020-07-18)\n==================\n\n- Add missing dependency on zope.event.\n- Fix raising ``AlreadyInTransaction`` error on the second and\n  subsequent calls to a loop when a transaction synchronizer raises an\n  error on the first call. See `issue 49\n  <https://github.com/NextThought/nti.transactions/issues/49>`_.\n\n4.0.0 (2019-12-13)\n==================\n\n- Require at least version 3.0 of the ``transaction`` package.\n\n- Drop dependency on the ``dm.transaction.aborthook`` package. That\n  functionality is now natively provided in transaction 3.0.\n\n\n3.1.1 (2019-12-10)\n==================\n\n- Fix logging of long duration commits. See `issue 44\n  <https://github.com/NextThought/nti.transactions/issues/44>`_.\n\n- Add logging and a metric\n  (``transaction.side_effect_free_violation``) for transactions that\n  claim to have no side effects, but which actually result in joined\n  resource managers. This can indicate unnecessarily throwing away\n  work. See `issue 45 <https://github.com/NextThought/nti.transactions/issues/45>`_.\n\n\n3.1.0 (2019-11-29)\n==================\n\n- Add support for Python 3.8.\n\n- Refactor internal implementation details. Instead of importing\n  everything from ``nti.transactions.transactions``, more specific\n  modules are used to group objects by function. The old imports\n  continue to work. In 4.0 they will generate a deprecation warning\n  and in 5.0 they will be removed.\n\n- Add a Pyramid tween to manage transactions and transaction retries.\n  Various settings can be configured as Pyramid deployment settings\n  (e.g., in the ini file).\n\n- Make the transaction loop increase the time it sleeps between\n  retries following the `random binary exponential backoff algorithm\n  <https://en.wikipedia.org/wiki/Exponential_backoff>`_ used by Ethernet.\n\n- Reduce the default number of attempts to 4 (one attempt and 3\n  retries). See `issue 35 <https://github.com/NextThought/nti.transactions/issues/35>`_.\n\n- Make the transaction loop emit more metrics. See `issue 31\n  <https://github.com/NextThought/nti.transactions/issues/31>`_.\n\n- Make commit logging now always happen at least at the debug level,\n  escalating to warning for long commits. It also includes the number\n  of retries taken and the amount of time spent sleeping. See `issue\n  32 <https://github.com/NextThought/nti.transactions/issues/32>`_.\n\n- Make the transaction loop emit events (using ``zope.event``) at certain parts of the\n  transaction lifecycle. See `issue 33 <https://github.com/NextThought/nti.transactions/issues/33>`_.\n\n3.0.0 (2019-09-06)\n==================\n\n- Make ``TransactionLoop`` place its transaction manager in explicit\n  mode. This can be faster and is easier to reason about, but forbids\n  the called handler from manually calling ``begin()``, ``abort()`` or\n  ``commit()``. See `issue 20\n  <https://github.com/NextThought/nti.transactions/issues/20>`_.\n\n- Move ``transaction.begin()`` out of the block of code that is\n  retried. Previously, an error there would probably be raised\n  *anyway* and not retried, unless a subclass had made customizations.\n\n- Add ``setUp`` and ``tearDown`` methods to TransactionLoop to give\n  subclasses a place to hook into the inners of the transaction loop.\n  This is particularly helpful if they need to do something after the\n  transaction manager has been put in explicit mode. See `issue 22\n  <https://github.com/NextThought/nti.transactions/issues/22>`_.\n\n2.0.1 (2019-09-03)\n==================\n\n- Fix compatibility with perfmetrics 3.0: drop ``from __future__\n  import unicode_literals``.\n\n\n2.0.0 (2018-07-20)\n==================\n\n- Use the new public ``isRetryableError`` in transaction 2.2. The\n  interface for this package is unchanged, but a major version bump of\n  a dependency necessitates a major bump here. See `issue 12\n  <https://github.com/NextThought/nti.transactions/issues/12>`_.\n\n- Test support for Python 3.7; remove test support for Python 3.4.\n\n- ``TransactionLoop`` is more careful to not keep traceback objects\n  around, especially on Python 2.\n\n1.1.1 (2018-07-19)\n==================\n\n- When the ``TransactionLoop`` raises a ``CommitFailedError`` from a\n  ``TypeError``, it preserves the original message.\n\n- Test support for Python 3.6.\n\n1.1.0 (2017-04-17)\n==================\n\n- Add a new ObjectDataManager that will attempt to execute after\n  other ObjectDataManagers.\n\n\n1.0.0 (2016-07-28)\n==================\n\n- Add support for Python 3.\n- Eliminate ZODB dependency. Instead of raising a\n  ``ZODB.POSException.StorageError`` for unexpected ``TypeErrors``\n  during commit, the new class\n  ``nti.transactions.interfaces.CommitFailedError`` is raised.\n- Introduce a new subclass of ``TransactionError``,\n  ``AbortFailedError`` that is raised when an abort fails due to a\n  system error.\n",
    "bugtrack_url": null,
    "license": "Apache",
    "summary": "NTI Transactions Utility",
    "version": "4.3.0",
    "project_urls": {
        "Homepage": "https://github.com/OpenNTI/nti.transactions"
    },
    "split_keywords": [
        "zodb",
        "transaction"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fc4aa4bd0fcddf737fa6a0751138740c6dc16683d2e31fdc59819440f22aa4a5",
                "md5": "7aa577043b447f12e6cff2f5c79bc320",
                "sha256": "f30a7194e8b613c1062c7ace33dad527d854704082e00497d0eaa558b2d9ee22"
            },
            "downloads": -1,
            "filename": "nti.transactions-4.3.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7aa577043b447f12e6cff2f5c79bc320",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 41478,
            "upload_time": "2023-05-05T21:09:45",
            "upload_time_iso_8601": "2023-05-05T21:09:45.641157Z",
            "url": "https://files.pythonhosted.org/packages/fc/4a/a4bd0fcddf737fa6a0751138740c6dc16683d2e31fdc59819440f22aa4a5/nti.transactions-4.3.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "374228d9a6b708bb798a07168f932bb03564625d526c3b663dd64f82c27ee7e2",
                "md5": "d8f1b859e2a511d8d3b59e1d6bc2d4d7",
                "sha256": "da61085c8e3d542212e46535ce47e286c77ec496a51eea4a55ebd5aa34978b50"
            },
            "downloads": -1,
            "filename": "nti.transactions-4.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d8f1b859e2a511d8d3b59e1d6bc2d4d7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 49749,
            "upload_time": "2023-05-05T21:09:47",
            "upload_time_iso_8601": "2023-05-05T21:09:47.963209Z",
            "url": "https://files.pythonhosted.org/packages/37/42/28d9a6b708bb798a07168f932bb03564625d526c3b663dd64f82c27ee7e2/nti.transactions-4.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-05 21:09:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "OpenNTI",
    "github_project": "nti.transactions",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "nti.transactions"
}
        
Elapsed time: 0.09909s