PKG-INFO 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. Metadata-Version: 1.1
  2. Name: django-celery-beat
  3. Version: 1.4.0
  4. Summary: Database-backed Periodic Tasks.
  5. Home-page: https://github.com/celery/django-celery-beat
  6. Author: Ask Solem
  7. Author-email: ask@celeryproject.org
  8. License: BSD
  9. Description: =====================================================================
  10. Database-backed Periodic Tasks
  11. =====================================================================
  12. |build-status| |coverage| |license| |wheel| |pyversion| |pyimp|
  13. :Version: 1.4.0
  14. :Web: http://django-celery-beat.readthedocs.io/
  15. :Download: http://pypi.python.org/pypi/django-celery-beat
  16. :Source: http://github.com/celery/django-celery-beat
  17. :Keywords: django, celery, beat, periodic task, cron, scheduling
  18. About
  19. =====
  20. This extension enables you to store the periodic task schedule in the
  21. database.
  22. The periodic tasks can be managed from the Django Admin interface, where you
  23. can create, edit and delete periodic tasks and how often they should run.
  24. Using the Extension
  25. ===================
  26. Usage and installation instructions for this extension are available
  27. from the `Celery documentation`_:
  28. http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html#using-custom-scheduler-classes
  29. .. _`Celery documentation`:
  30. http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html#using-custom-scheduler-classes
  31. Important Warning about Time Zones
  32. ==================================
  33. .. warning::
  34. If you change the Django ``TIME_ZONE`` setting your periodic task schedule
  35. will still be based on the old timezone.
  36. To fix that you would have to reset the "last run time" for each periodic
  37. task::
  38. >>> from django_celery_beat.models import PeriodicTask, PeriodicTasks
  39. >>> PeriodicTask.objects.all().update(last_run_at=None)
  40. >>> for task in PeriodicTask.objects.all():
  41. >>> PeriodicTasks.changed(task)
  42. Note that this will reset the state as if the periodic tasks have never run
  43. before.
  44. Models
  45. ======
  46. - ``django_celery_beat.models.PeriodicTask``
  47. This model defines a single periodic task to be run.
  48. It must be associated with a schedule, which defines how often the task should
  49. run.
  50. - ``django_celery_beat.models.IntervalSchedule``
  51. A schedule that runs at a specific interval (e.g. every 5 seconds).
  52. - ``django_celery_beat.models.CrontabSchedule``
  53. A schedule with fields like entries in cron:
  54. ``minute hour day-of-week day_of_month month_of_year``.
  55. - ``django_celery_beat.models.PeriodicTasks``
  56. This model is only used as an index to keep track of when the schedule has
  57. changed.
  58. Whenever you update a ``PeriodicTask`` a counter in this table is also
  59. incremented, which tells the ``celery beat`` service to reload the schedule
  60. from the database.
  61. If you update periodic tasks in bulk, you will need to update the counter
  62. manually::
  63. >>> from django_celery_beat.models import PeriodicTasks
  64. >>> PeriodicTasks.changed()
  65. Example creating interval-based periodic task
  66. ---------------------------------------------
  67. To create a periodic task executing at an interval you must first
  68. create the interval object::
  69. >>> from django_celery_beat.models import PeriodicTask, IntervalSchedule
  70. # executes every 10 seconds.
  71. >>> schedule, created = IntervalSchedule.objects.get_or_create(
  72. ... every=10,
  73. ... period=IntervalSchedule.SECONDS,
  74. ... )
  75. That's all the fields you need: a period type and the frequency.
  76. You can choose between a specific set of periods:
  77. - ``IntervalSchedule.DAYS``
  78. - ``IntervalSchedule.HOURS``
  79. - ``IntervalSchedule.MINUTES``
  80. - ``IntervalSchedule.SECONDS``
  81. - ``IntervalSchedule.MICROSECONDS``
  82. .. note::
  83. If you have multiple periodic tasks executing every 10 seconds,
  84. then they should all point to the same schedule object.
  85. There's also a "choices tuple" available should you need to present this
  86. to the user::
  87. >>> IntervalSchedule.PERIOD_CHOICES
  88. Now that we have defined the schedule object, we can create the periodic task
  89. entry::
  90. >>> PeriodicTask.objects.create(
  91. ... interval=schedule, # we created this above.
  92. ... name='Importing contacts', # simply describes this periodic task.
  93. ... task='proj.tasks.import_contacts', # name of task.
  94. ... )
  95. Note that this is a very basic example, you can also specify the arguments
  96. and keyword arguments used to execute the task, the ``queue`` to send it
  97. to[*], and set an expiry time.
  98. Here's an example specifying the arguments, note how JSON serialization is
  99. required::
  100. >>> import json
  101. >>> from datetime import datetime, timedelta
  102. >>> PeriodicTask.objects.create(
  103. ... interval=schedule, # we created this above.
  104. ... name='Importing contacts', # simply describes this periodic task.
  105. ... task='proj.tasks.import_contacts', # name of task.
  106. ... args=json.dumps(['arg1', 'arg2']),
  107. ... kwargs=json.dumps({
  108. ... 'be_careful': True,
  109. ... }),
  110. ... expires=datetime.utcnow() + timedelta(seconds=30)
  111. ... )
  112. .. [*] you can also use low-level AMQP routing using the ``exchange`` and
  113. ``routing_key`` fields.
  114. Example creating crontab-based periodic task
  115. --------------------------------------------
  116. A crontab schedule has the fields: ``minute``, ``hour``, ``day_of_week``,
  117. ``day_of_month`` and ``month_of_year`, so if you want the equivalent
  118. of a ``30 * * * *`` (execute every 30 minutes) crontab entry you specify::
  119. >>> from django_celery_beat.models import CrontabSchedule, PeriodicTask
  120. >>> schedule, _ = CrontabSchedule.objects.get_or_create(
  121. ... minute='30',
  122. ... hour='*',
  123. ... day_of_week='*',
  124. ... day_of_month='*',
  125. ... month_of_year='*',
  126. ... timezone=pytz.timezone('Canada/Pacific')
  127. ... )
  128. The crontab schedule is linked to a specific timezone using the 'timezone' input parameter.
  129. Then to create a periodic task using this schedule, use the same approach as
  130. the interval-based periodic task earlier in this document, but instead
  131. of ``interval=schedule``, specify ``crontab=schedule``::
  132. >>> PeriodicTask.objects.create(
  133. ... crontab=schedule,
  134. ... name='Importing contacts',
  135. ... task='proj.tasks.import_contacts',
  136. ... )
  137. Temporarily disable a periodic task
  138. -----------------------------------
  139. You can use the ``enabled`` flag to temporarily disable a periodic task::
  140. >>> periodic_task.enabled = False
  141. >>> periodic_task.save()
  142. Installation
  143. ============
  144. You can install django-celery-beat either via the Python Package Index (PyPI)
  145. or from source.
  146. To install using `pip`,::
  147. $ pip install -U django-celery-beat
  148. Downloading and installing from source
  149. --------------------------------------
  150. Download the latest version of django-celery-beat from
  151. http://pypi.python.org/pypi/django-celery-beat
  152. You can install it by doing the following,::
  153. $ tar xvfz django-celery-beat-0.0.0.tar.gz
  154. $ cd django-celery-beat-0.0.0
  155. $ python setup.py build
  156. # python setup.py install
  157. The last command must be executed as a privileged user if
  158. you are not currently using a virtualenv.
  159. Using the development version
  160. -----------------------------
  161. With pip
  162. ~~~~~~~~
  163. You can install the latest snapshot of django-celery-beat using the following
  164. pip command::
  165. $ pip install https://github.com/celery/django-celery-beat/zipball/master#egg=django-celery-beat
  166. TZ Awareness:
  167. -------------
  168. If you have a project that is time zone naive, you can set `DJANGO_CELERY_BEAT_TZ_AWARE=False` in your settings file.
  169. .. |build-status| image:: https://secure.travis-ci.org/celery/django-celery-beat.svg?branch=master
  170. :alt: Build status
  171. :target: https://travis-ci.org/celery/django-celery-beat
  172. .. |coverage| image:: https://codecov.io/github/celery/django-celery-beat/coverage.svg?branch=master
  173. :target: https://codecov.io/github/celery/django-celery-beat?branch=master
  174. .. |license| image:: https://img.shields.io/pypi/l/django-celery-beat.svg
  175. :alt: BSD License
  176. :target: https://opensource.org/licenses/BSD-3-Clause
  177. .. |wheel| image:: https://img.shields.io/pypi/wheel/django-celery-beat.svg
  178. :alt: django-celery-beat can be installed via wheel
  179. :target: http://pypi.python.org/pypi/django-celery-beat/
  180. .. |pyversion| image:: https://img.shields.io/pypi/pyversions/django-celery-beat.svg
  181. :alt: Supported Python versions.
  182. :target: http://pypi.python.org/pypi/django-celery-beat/
  183. .. |pyimp| image:: https://img.shields.io/pypi/implementation/django-celery-beat.svg
  184. :alt: Support Python implementations.
  185. :target: http://pypi.python.org/pypi/django-celery-beat/
  186. Keywords: django celery beat periodic task database
  187. Platform: any
  188. Classifier: Development Status :: 5 - Production/Stable
  189. Classifier: License :: OSI Approved :: BSD License
  190. Classifier: Programming Language :: Python
  191. Classifier: Programming Language :: Python :: 2
  192. Classifier: Programming Language :: Python :: 2.7
  193. Classifier: Programming Language :: Python :: 3
  194. Classifier: Programming Language :: Python :: 3.4
  195. Classifier: Programming Language :: Python :: 3.5
  196. Classifier: Programming Language :: Python :: Implementation :: CPython
  197. Classifier: Programming Language :: Python :: Implementation :: PyPy
  198. Classifier: Framework :: Django
  199. Classifier: Framework :: Django :: 1.8
  200. Classifier: Framework :: Django :: 1.9
  201. Classifier: Framework :: Django :: 1.10
  202. Classifier: Framework :: Django :: 1.11
  203. Classifier: Framework :: Django :: 2.0
  204. Classifier: Operating System :: OS Independent
  205. Classifier: Topic :: Communications
  206. Classifier: Topic :: System :: Distributed Computing
  207. Classifier: Topic :: Software Development :: Libraries :: Python Modules