{ "info": { "author": "Ben Timby", "author_email": "btimby@smartfile.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "Operating System :: OS Independent", "Programming Language :: Python" ], "description": ".. image:: https://travis-ci.org/btimby/django-tpq.svg?branch=master\r\n :alt: Travis CI Status\r\n :target: https://travis-ci.org/btimby/django-tpq\r\n\r\n.. image:: https://coveralls.io/repos/github/btimby/django-tpq/badge.svg?branch=master\r\n :target: https://coveralls.io/github/btimby/django-tpq?branch=master\r\n :alt: Code Coverage\r\n\r\n.. image:: https://badge.fury.io/py/django-tpq.svg\r\n :target: https://badge.fury.io/py/django-tpq\r\n\r\nTrivial Postgres Queue for Django\r\n=================================\r\n\r\nThis is a Django application that integrates\r\n`tpq `_. This application provides basic\r\nmessage queue capabilities as well as a high-level futures implementation.\r\n\r\nMessage Queue\r\n-------------\r\n\r\nTo implement a message queue, you must first create a model derived from the\r\nabstract ``BaseQueue`` model. Once done, create a migration for that model, then\r\nedit the migration to add some additional database objects (tpq does this for\r\nyou, but you must call it from the migration). Then migrate and use your queue.\r\n\r\n.. code:: python\r\n\r\n from django_tpq.main.models import BaseQueue\r\n\r\n class MyQueue(BaseQueue):\r\n pass\r\n\r\n::\r\n\r\n $ python manage.py makemigrations\r\n\r\nNow edit the migration and add the RunPython step as is done with the futures\r\n`initial migration `_.\r\nYou will also need to customize the model name in the ``forward`` function.\r\n\r\n::\r\n\r\n $ python manage.py migrate\r\n\r\n\r\n.. code:: python\r\n\r\n from myapp.models import MyQueue\r\n\r\n MyQueue.objects.enqueue({'field': 'value'})\r\n message = MyQueue.objects.dequeue()\r\n\r\nFutures\r\n-------\r\n\r\nUsing the above as a foundation, a simple Futures implementation is provided.\r\nFirst you must register any function you wish to call asynchronously as a future.\r\nThen call that future. You can optionally wait or poll for the results.\r\n\r\n.. code:: python\r\n\r\n import time\r\n\r\n from django_tpq.futures.decorators import future\r\n\r\n\r\n @future()\r\n def long_running_function(*args):\r\n time.sleep(100)\r\n\r\n # You can execute the future without waiting for a result. This returns\r\n # immediately and your future runs within another process (fire and forget).\r\n long_running_function.async('argument_1')\r\n\r\n # Or you can poll for the results (or check after you do some other work).\r\n f = long_running_function.async('argument_1')\r\n\r\n while True:\r\n try:\r\n r = f.result()\r\n except Exception:\r\n # Exceptions are re-raised.\r\n LOGGER.exception('Future failed', exc_info)\r\n break\r\n else:\r\n break\r\n time.sleep(10)\r\n\r\n print(r)\r\n\r\n # Or optionally, you can block waiting for the result.\r\n f = long_running_function.call('argument_1')\r\n\r\n try:\r\n r = f.result(wait=0)\r\n except Exception:\r\n # Exceptions are re-raised.\r\n LOGGER.exception('Future failed', exc_info)\r\n\r\n print(r)\r\n\r\nFunction calls are dispatched via a message queue. Arguments are pickled, so you\r\ncan send any picklable Python objects. Results are delivered via your configured\r\ncache. By default the ``default`` cache is used, but you can use the\r\n``FUTURES_RESULT_CACHE`` setting to provide an alternate name for the Django\r\ncache you want to be used for results. Results have a TTL of 60 minutes by\r\ndefault but you can adjust this using the ``FUTURES_RESULT_TTL`` setting.\r\n\r\n\\* Note that if you use a very short TTL and start polling after it has already\r\nexpired, you will never see results. Further, if you use wait, you will wait\r\nforever.\r\n\r\nFutures are executed by a daemon started using a Django management command.\r\n\r\n::\r\n\r\n $ python manage.py futures_executor --help\r\n usage: manage.py futures_executor [-h] [--version] [-v {0,1,2,3}]\r\n [--settings SETTINGS]\r\n [--pythonpath PYTHONPATH] [--traceback]\r\n [--no-color] [--queue_name QUEUE_NAME]\r\n [--once] [--wait WAIT]\r\n\r\n Daemon to execute futures.\r\n\r\n optional arguments:\r\n -h, --help show this help message and exit\r\n --version show program's version number and exit\r\n -v {0,1,2,3}, --verbosity {0,1,2,3}\r\n Verbosity level; 0=minimal output, 1=normal output,\r\n 2=verbose output, 3=very verbose output\r\n --settings SETTINGS The Python path to a settings module, e.g.\r\n \"myproject.settings.main\". If this isn't provided, the\r\n DJANGO_SETTINGS_MODULE environment variable will be\r\n used.\r\n --pythonpath PYTHONPATH\r\n A directory to add to the Python path, e.g.\r\n \"/home/djangoprojects/myproject\".\r\n --traceback Raise on CommandError exceptions\r\n --no-color Don't colorize the command output.\r\n --queue_name QUEUE_NAME\r\n The queue to monitor. default: futures.FutureQueue\r\n --once Run one, then exit.\r\n --wait WAIT Wait time. Useful with --once.\r\n\r\nSome future statistics are also stored in your Postgres database for reporting\r\npurposes.\r\n\r\n.. code:: python\r\n\r\n from django_tpq.futures.models import FutureStat\r\n\r\n FutureStat.objects.all()\r\n\r\nThe ``FutureStat`` model has the following fields.\r\n\r\n- ``name`` - The python module.function of the future.\r\n- ``running`` - The number of currently executing futures of this type.\r\n- ``total`` - The total number of executed futures of this type.\r\n- ``failed`` - The number of futures resulting in an exception.\r\n- ``last_seen`` - The timestamp of the most recent execution of the future.\r\n- ``first_seen`` - The timestamp of the least recent execution of the future.\r\n\r\nBeing a model, you can use the Django ORM to report on these fields any way you\r\nsee fit.", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/btimby/tpq/", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "django-tpq", "package_url": "https://pypi.org/project/django-tpq/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-tpq/", "project_urls": { "Homepage": "https://github.com/btimby/tpq/" }, "release_url": "https://pypi.org/project/django-tpq/1.9/", "requires_dist": null, "requires_python": "", "summary": "Trivial Postgres Queue for Django", "version": "1.9" }, "last_serial": 2874565, "releases": { "1.9": [ { "comment_text": "", "digests": { "md5": "c53e01b3c561d9175ee83af68c265db9", "sha256": "7c6985ff1a12c2373d403678d5fe4b603bc9267cdbcdc89bbf8e8fabc2642227" }, "downloads": -1, "filename": "django_tpq-1.9.tar.gz", "has_sig": false, "md5_digest": "c53e01b3c561d9175ee83af68c265db9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3683, "upload_time": "2017-05-15T04:35:02", "url": "https://files.pythonhosted.org/packages/63/bb/019783c009bb4a46d2f1a2494d00867d33edd9b6c7d06d6caa663886d171/django_tpq-1.9.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c53e01b3c561d9175ee83af68c265db9", "sha256": "7c6985ff1a12c2373d403678d5fe4b603bc9267cdbcdc89bbf8e8fabc2642227" }, "downloads": -1, "filename": "django_tpq-1.9.tar.gz", "has_sig": false, "md5_digest": "c53e01b3c561d9175ee83af68c265db9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3683, "upload_time": "2017-05-15T04:35:02", "url": "https://files.pythonhosted.org/packages/63/bb/019783c009bb4a46d2f1a2494d00867d33edd9b6c7d06d6caa663886d171/django_tpq-1.9.tar.gz" } ] }