DESCRIPTION.rst 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. huey - a little task queue
  2. ==========================
  3. .. image:: http://media.charlesleifer.com/blog/photos/huey-logo.png
  4. a lightweight alternative.
  5. * written in python (2.7+, 3.4+)
  6. * optional dependency on the Python Redis client
  7. supports:
  8. * multi-process, multi-thread or greenlet task execution models
  9. * schedule tasks to execute at a given time, or after a given delay
  10. * schedule recurring tasks, like a crontab
  11. * retry tasks that fail automatically
  12. * task result storage
  13. * task locking
  14. * task pipelines and chains
  15. .. image:: http://i.imgur.com/2EpRs.jpg
  16. .. image:: https://api.travis-ci.org/coleifer/huey.svg?branch=master
  17. Huey's API
  18. ----------
  19. .. code-block:: python
  20. from huey import RedisHuey, crontab
  21. huey = RedisHuey('my-app', host='redis.myapp.com')
  22. @huey.task()
  23. def add_numbers(a, b):
  24. return a + b
  25. @huey.periodic_task(crontab(minute='0', hour='3'))
  26. def nightly_backup():
  27. sync_all_data()
  28. To run the consumer with 4 worker processes:
  29. .. code-block:: console
  30. $ huey_consumer.py my_app.huey -k process -w 4
  31. To enqueue a task to add two numbers and print the result:
  32. .. code-block:: python
  33. res = add_numbers(1, 2) # Enqueues task.
  34. print(res.get()) # Prints "3".
  35. To schedule two numbers to be added in 10 seconds:
  36. .. code-block:: python
  37. res = add_numbers.schedule(args=(1, 2), delay=10)
  38. # Attempt to get result without blocking.
  39. print(res.get(False)) # returns None.
  40. # Block until result is ready and print.
  41. print(res.get()) # after 10 seconds, prints "3".
  42. Brokers
  43. -------
  44. To use Huey with Redis (**recommended**):
  45. .. code-block:: python
  46. from huey import RedisHuey
  47. huey = RedisHuey()
  48. To use Huey with SQLite (`docs <http://huey.readthedocs.io/en/latest/contrib.html#sqlite-storage>`_):
  49. .. code-block:: python
  50. from huey.contrib.sqlitedb import SqliteHuey
  51. huey = SqliteHuey('my-app-queue.db')
  52. To run Huey within the parent process using background greenlets (`docs <http://huey.readthedocs.io/en/latest/contrib.html#mini-huey>`_):
  53. .. code-block:: python
  54. from huey.contrib.minimal import MiniHuey
  55. huey = MiniHuey()
  56. huey.start() # Spawns scheduler background thread and returns immediately.
  57. To run Huey with a simple Python broker (**should not be used in production**),
  58. install `simpledb <https://github.com/coleifer/simpledb>`_ and run:
  59. .. code-block:: python
  60. from huey.contrib.simple_storage import SimpleHuey
  61. huey = SimpleHuey()
  62. # Be sure to run the Python broker process, e.g.:
  63. # $ python simpledb.py # Starts Python broker.
  64. Documentation
  65. ----------------
  66. `See Huey documentation <https://huey.readthedocs.io/>`_.
  67. Project page
  68. ---------------
  69. `See source code and issue tracker on Github <https://github.com/coleifer/huey/>`_.
  70. Huey is named in honor of my cat:
  71. .. image:: http://m.charlesleifer.com/t/800x-/blog/photos/p1473037658.76.jpg?key=mD9_qMaKBAuGPi95KzXYqg