freshcrate
Home > Databases > django-celery-beat

django-celery-beat

Database-backed Periodic Tasks.

Description

===================================================================== Database-backed Periodic Tasks ===================================================================== |build-status| |coverage| |license| |wheel| |pyversion| |pyimp| :Version: 2.8.1 :Web: http://django-celery-beat.readthedocs.io/ :Download: http://pypi.python.org/pypi/django-celery-beat :Source: http://github.com/celery/django-celery-beat :DeepWiki: |deepwiki| :Keywords: django, celery, beat, periodic task, cron, scheduling About ===== This extension enables you to store the periodic task schedule in the database. The periodic tasks can be managed from the Django Admin interface, where you can create, edit and delete periodic tasks and how often they should run. Using the Extension =================== Usage and installation instructions for this extension are available from the `Celery documentation`_. .. _`Celery documentation`: http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html#using-custom-scheduler-classes Important Warning about Time Zones ================================== .. warning:: If you change the Django ``TIME_ZONE`` setting your periodic task schedule will still be based on the old timezone. To fix that you would have to reset the "last run time" for each periodic task: .. code-block:: Python >>> from django_celery_beat.models import PeriodicTask, PeriodicTasks >>> PeriodicTask.objects.all().update(last_run_at=None) >>> PeriodicTasks.update_changed() .. note:: This will reset the state as if the periodic tasks have never run before. Models ====== - ``django_celery_beat.models.PeriodicTask`` This model defines a single periodic task to be run. It must be associated with a schedule, which defines how often the task should run. - ``django_celery_beat.models.IntervalSchedule`` A schedule that runs at a specific interval (e.g. every 5 seconds). - ``django_celery_beat.models.CrontabSchedule`` A schedule with fields like entries in cron: ``minute hour day-of-week day_of_month month_of_year``. - ``django_celery_beat.models.PeriodicTasks`` This model is only used as an index to keep track of when the schedule has changed. Whenever you update a ``PeriodicTask`` a counter in this table is also incremented, which tells the ``celery beat`` service to reload the schedule from the database. If you update periodic tasks in bulk, you will need to update the counter manually: .. code-block:: Python >>> from django_celery_beat.models import PeriodicTasks >>> PeriodicTasks.update_changed() Example creating interval-based periodic task --------------------------------------------- To create a periodic task executing at an interval you must first create the interval object: .. code-block:: Python >>> from django_celery_beat.models import PeriodicTask, IntervalSchedule # executes every 10 seconds. >>> schedule, created = IntervalSchedule.objects.get_or_create( ... every=10, ... period=IntervalSchedule.SECONDS, ... ) That's all the fields you need: a period type and the frequency. You can choose between a specific set of periods: - ``IntervalSchedule.DAYS`` - ``IntervalSchedule.HOURS`` - ``IntervalSchedule.MINUTES`` - ``IntervalSchedule.SECONDS`` - ``IntervalSchedule.MICROSECONDS`` .. note:: If you have multiple periodic tasks executing every 10 seconds, then they should all point to the same schedule object. There's also a "choices tuple" available should you need to present this to the user: .. code-block:: Python >>> IntervalSchedule.PERIOD_CHOICES Now that we have defined the schedule object, we can create the periodic task entry: .. code-block:: Python >>> PeriodicTask.objects.create( ... interval=schedule, # we created this above. ... name='Importing contacts', # simply describes this periodic task. ... task='proj.tasks.import_contacts', # name of task. ... ) Note that this is a very basic example, you can also specify the arguments and keyword arguments used to execute the task, the ``queue`` to send it to[*], and set an expiry time. Here's an example specifying the arguments, note how JSON serialization is required: .. code-block:: Python >>> import json >>> from datetime import datetime, timedelta >>> PeriodicTask.objects.create( ... interval=schedule, # we created this above. ... name='Importing contacts', # simply describes this periodic task. ... task='proj.tasks.import_contacts', # name of task. ... args=json.dumps(['arg1', 'arg2']), ... kwargs=json.dumps({ ... 'be_careful': True, ... }), ... expires=datetime.utcnow() + timedelta(seconds=30) ... ) .. [*] you can also use low-level AMQP routing using the

Release History

VersionChangesUrgencyDate
2.9.0Imported from PyPI (2.9.0)Low4/21/2026
v2.9.0## What's Changed * Added DeepWiki to README by @Nusnus in https://github.com/celery/django-celery-beat/pull/893 * refactor: use in operator instead of regex operator in crontab query to fix mssql regression by @alirafiei75 in https://github.com/celery/django-celery-beat/pull/900 * refactor: tzaware crontab is due method by @alirafiei75 in https://github.com/celery/django-celery-beat/pull/899 * feat: enable translation to PeriodicTaskInline verbose name by @thalesbarbosab in https://github.cLow2/28/2026
v2.8.1## What's Changed * [pre-commit.ci] pre-commit autoupdate by @pre-commit-ci in https://github.com/celery/django-celery-beat/pull/876 * [pre-commit.ci] pre-commit autoupdate by @pre-commit-ci in https://github.com/celery/django-celery-beat/pull/880 * Refactor / all_as_schedule crontab query optimization by @alirafiei75 in https://github.com/celery/django-celery-beat/pull/879 * [pre-commit.ci] pre-commit autoupdate by @pre-commit-ci in https://github.com/celery/django-celery-beat/pull/884 * CLow5/13/2025
v2.8.0## What's Changed * Added a new step to upload code coverage report to codecov by @Nusnus in https://github.com/celery/django-celery-beat/pull/793 * Changed codecov branch from master to main in README.rst by @Nusnus in https://github.com/celery/django-celery-beat/pull/794 * requirements/runtime.txt: Django>=2.2,<6.0 by @cclauss in https://github.com/celery/django-celery-beat/pull/792 * [pre-commit.ci] pre-commit autoupdate by @pre-commit-ci in https://github.com/celery/django-celery-beat/puLow4/16/2025
v2.7.0## What's Changed * fix display of long name day of the week by @Akay7 in https://github.com/celery/django-celery-beat/pull/745 * Adding inline to each schedule admin to show PeriodicTasks using the schedule by @truthdoug in https://github.com/celery/django-celery-beat/pull/743 * relaxed django upper version limit to 5.1 by @auvipy in https://github.com/celery/django-celery-beat/pull/756 * some fixes in fr translation by @arthru in https://github.com/celery/django-celery-beat/pull/760 * StaLow8/21/2024
v2.6.0This release adds support for Django v5.0 and Python 3.12. ## What's Changed * Avoid crash when can not get human readable description by @nijel in https://github.com/celery/django-celery-beat/pull/648 * Update codeql-analysis.yml by @auvipy in https://github.com/celery/django-celery-beat/pull/653 * Fix CI: Change assert self.app.timezone.zone to assert self.app.timezone.key by @stasfilin in https://github.com/celery/django-celery-beat/pull/664 * drop django 4.0 from CI to avoid securityLow3/3/2024
v2.5.0## What's Changed * [pre-commit.ci] pre-commit autoupdate by @pre-commit-ci in https://github.com/celery/django-celery-beat/pull/601 * Fix typo in settings for celery beat scheduler by @laurent-brisbois in https://github.com/celery/django-celery-beat/pull/603 * prefetch_related on PeriodicTaskQuerySet.enabled issue:https://github… by @jahazieldom in https://github.com/celery/django-celery-beat/pull/609 * delete tidelift alignment by @auvipy in https://github.com/celery/django-celery-beat/pulLow3/14/2023
v2.4.0## What's Changed * add `zh_hans` translate by @tor-web3 in https://github.com/celery/django-celery-beat/pull/554 * Fixed error path for zh-Hans translate (#548) by @954-Ivory in https://github.com/celery/django-celery-beat/pull/570 * Replace favicon.ico with an actual ICO file by @mapreri in https://github.com/celery/django-celery-beat/pull/582 * Django>=3.2,<4.2 by @auvipy in https://github.com/celery/django-celery-beat/pull/567 * test: add django 41 into tox by @goatwu1993 in https://gitLow10/19/2022
v2.3.0## What's Changed * Remove duplication in Changelog by @DmytroLitvinov in https://github.com/celery/django-celery-beat/pull/421 * Small fixes on French locale by @raphodn in https://github.com/celery/django-celery-beat/pull/426 * Declare support for Python 3.9 by @D3X in https://github.com/celery/django-celery-beat/pull/424 * relax django runtime version by @auvipy in https://github.com/celery/django-celery-beat/pull/435 * (docs) Update Changelog (#422) by @DmytroLitvinov in https://github.Low6/4/2022
v2.2.12.2.1 ===== :release-date: 2021-07-02 11:15 a.m. UTC+6:00 :release-by: Asif Saif Uddin - Enable Django 3.2 CI and add default_auto_field - Fix locale in dir tree - Do not blindly delete duplicate schedules (#389) - used python:3.8-slim for lighter builds - Do not blindly delete duplicate schedules (#389) Low7/2/2021
v2.2.02.2.0 ===== :release-date: 2021-01-19 2:30 p.m. UTC+6:00 :release-by: Asif Saif Uddin - Fixed compatibility with django-timezone-field>=4.1.0 - Fixed deprecation warnings: 'assertEquals' in tests. - Fixed SolarSchedule event choices i18n support. - Updated 'es' .po file metadata - Update 'fr' .po file metadata - New schema migrations for SolarSchedule events choices changes in models.Low1/19/2021
v2.1.0Release v2.1.0Low10/20/2020
2.0.0Release 2.0.0Low3/18/2020
1.6.0Release 1.6.0Low2/26/2020
1.5.0Release 1.5.0Low12/10/2019
v1.4.0Release v1.4.0Low5/13/2019
v1.3.0Release v1.3.0Low12/9/2018
v1.2.0Release v1.2.0Low11/12/2018
v1.1.1Release v1.1.1Low2/18/2018
v1.1.0Release v1.1.0Low10/30/2017

Dependencies & License Audit

Loading dependencies...

Similar Packages

django-celery-resultsCelery result backends for Django.2.6.0
ibmcloudantPython client library for IBM Cloudant0.11.5
neo4jNeo4j Bolt driver for Python6.1.0
pineconePinecone client and SDK8.1.2
asyncpgAn asyncio PostgreSQL driver0.31.0