{ "info": { "author": "Silas Boyd-Wickizer", "author_email": "silas@godaddy.com", "bugtrack_url": null, "classifiers": [], "description": "django\\_transaction\\_barrier - transaction barriers for Django and Celery\r\n=========================================================================\r\n\r\ndjango\\_transaction\\_barrier provides a barrier-like abstraction for\r\ntransactions. A Django application developer can use a \"transaction\r\nbarrier\" to spawn a task within a transaction and guarantee that the\r\ntask blocks until it's able to access the updates made in the\r\ntransaction. django\\_transaction\\_barrier is designed with\r\n`Celery `__ in mind and provides a Celery\r\ntask base class. Using the base class it's easy to write code that\r\natomically modifies the database and spawns a Celery task that executes\r\nafter the transaction commits.\r\n\r\nInstallation\r\n------------\r\n\r\nInstall from source or use pip:\r\n\r\n.. code:: sh\r\n\r\n pip install django_transaction_barrier\r\n\r\nand add \"django\\_transaction\\_barrier\" to INSTALLED\\_APPS in\r\nsettings.py:\r\n\r\n.. code:: python\r\n\r\n INSTALLED_APPS = (\r\n 'django_transaction_barrier',\r\n ...\r\n )\r\n\r\nUsage\r\n-----\r\n\r\n.. code:: python\r\n\r\n from celery import task\r\n from django.db import transaction\r\n from django_transaction_barrier.celery import TransactionBarrierTask\r\n\r\n @task(base=TransactionBarrierTask)\r\n def do_something_task(model_id):\r\n value = Model.objects.get(id=model_id).value\r\n ...\r\n\r\n @transaction.atomic\r\n def kick_off_task(model, value):\r\n model.value = value\r\n do_something_task.apply_async_with_barrier(args=(model.id,))\r\n model.save()\r\n\r\nDetails\r\n-------\r\n\r\nIf an application spawns an asynchronous TransactionBarrierTask the task\r\nis guaranteed to execute eventually (assuming a durable task queue)\r\nafter the transaction commits. If the transaction aborts, the task\r\nraises a TransactionAborted exception and does not execute. In\r\nautocommit mode (i.e., \"outside of a transaction\")\r\nTransactionBarrierTasks behave like normal Celery tasks.\r\n\r\nIf an application synchrnously executes a TransactionBarrierTask (e.g.,\r\nwith Celery eager mode) within a transaction, the task executes\r\nimmediately without waiting for the transaction to commit.\r\n\r\nImplementation\r\n--------------\r\n\r\ndjango\\_transaction\\_barrier implements transaction barriers using row\r\ninsertion to signify a committed transaction and some DB-specifc logic\r\nto detect an abort.\r\n\r\nRelated\r\n-------\r\n\r\n- https://pypi.python.org/pypi/django-transaction-signals-do-not-use/1.0\r\n- https://django-transaction-hooks.readthedocs.org/en/latest/\r\n- https://code.djangoproject.com/ticket/14051\r\n- https://github.com/nickbruun/django\\_atomic\\_celery\r\n\r\ndjango\\_transaction\\_barrier provides diffferent semantics than related\r\nprojects. It guarantees TransactionBarrierTask execution if the\r\ntransaction commits. Most related projects rely on monkey patching\r\nDjango's database backends to provide post commit hooks, which results\r\nin a race: they (non-atomically) commit the transaction and then execute\r\nthe post commit hook, so they do not guarantee task execution.\r\n\r\nAs noted above, if an application synchrnously executes a\r\nTransactionBarrierTask (e.g., with Celery eager mode) within a\r\ntransaction, the task executes immediately without waiting for the\r\ntransaction to commit.\r\n\r\nTests\r\n-----\r\n\r\n.. code:: sh\r\n\r\n docker build -t tests . && docker run tests\r\n\r\nTODO\r\n----\r\n\r\n- Add support for a mysql backend.", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/godaddy/django_transaction_barrier/tarball/0.3", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/godaddy/django_transaction_barrier", "keywords": "django, transaction, celery, atomic", "license": "The MIT License (MIT)", "maintainer": "Silas Boyd-Wickizer", "maintainer_email": "silas@godaddy.com", "name": "django-transaction-barrier", "package_url": "https://pypi.org/project/django-transaction-barrier/", "platform": "", "project_url": "https://pypi.org/project/django-transaction-barrier/", "project_urls": { "Download": "https://github.com/godaddy/django_transaction_barrier/tarball/0.3", "Homepage": "https://github.com/godaddy/django_transaction_barrier" }, "release_url": "https://pypi.org/project/django-transaction-barrier/0.3/", "requires_dist": null, "requires_python": null, "summary": "Transaction barriers for Django and Celery.", "version": "0.3" }, "last_serial": 1433841, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "6e95c52f34ca8dfccb31e019cc05c993", "sha256": "2457d74b4cacd860f5a8e2979188cab35691ed71fef38c7c9cf362474c51594f" }, "downloads": -1, "filename": "django-transaction-barrier-0.1.tar.gz", "has_sig": false, "md5_digest": "6e95c52f34ca8dfccb31e019cc05c993", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7565, "upload_time": "2015-01-12T20:55:48", "url": "https://files.pythonhosted.org/packages/08/92/bf3c68ff1f3c71546531e42c3f61e8798bf7b3596fa436242fe0531c2692/django-transaction-barrier-0.1.tar.gz" } ], "0.2": [], "0.3": [ { "comment_text": "", "digests": { "md5": "6b5d1345be49e66a7e7e2586c9d50957", "sha256": "6e4a476189a15f3361591c26ad316a803a840ce0b3ccd69a2d68a2c27b29e651" }, "downloads": -1, "filename": "django-transaction-barrier-0.3.tar.gz", "has_sig": false, "md5_digest": "6b5d1345be49e66a7e7e2586c9d50957", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7551, "upload_time": "2015-02-23T00:13:21", "url": "https://files.pythonhosted.org/packages/99/6a/bd815d16a8937ee9995b9e53823600ce4a9c27e0e8a15a527ac49857812c/django-transaction-barrier-0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6b5d1345be49e66a7e7e2586c9d50957", "sha256": "6e4a476189a15f3361591c26ad316a803a840ce0b3ccd69a2d68a2c27b29e651" }, "downloads": -1, "filename": "django-transaction-barrier-0.3.tar.gz", "has_sig": false, "md5_digest": "6b5d1345be49e66a7e7e2586c9d50957", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7551, "upload_time": "2015-02-23T00:13:21", "url": "https://files.pythonhosted.org/packages/99/6a/bd815d16a8937ee9995b9e53823600ce4a9c27e0e8a15a527ac49857812c/django-transaction-barrier-0.3.tar.gz" } ] }