Skip to main content

A fork of django-celery-beat that you can install with Django 6.1.

Build status coverage BSD License Supported Python versions. Support Python implementations.

PyPI:

django-celery-beat-next

Import:

django_celery_beat

Source:

https://github.com/azataiot/django-celery-beat-next

Upstream:

https://github.com/celery/django-celery-beat

Issue:

celery/django-celery-beat#1079

Keywords:

django, celery, beat, periodic task, cron, scheduling

This fork is not an official Celery project.

Why this fork exists

django-celery-beat 2.9.0 requires Django<6.1. A lockfile cannot take Django 6.1 while that requirement stands.

Upstream main already runs the 6.1 tests. The requirement there is Django>=3.2.25,<6.2. See celery/django-celery-beat#1079 and celery/django-celery-beat#1042.

This repo follows that main branch. The import and the Django app label stay django_celery_beat, so you do not touch migrations. Swap the dependency name only. Leave INSTALLED_APPS as it is.

Do not depend on both packages at once. They install the same module.

If a later django-celery-beat release accepts Django 6.1, switch to that release. Then drop this fork.

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.

Important Warning about Time Zones

>>> from django_celery_beat.models import PeriodicTask, PeriodicTasks
>>> PeriodicTask.objects.all().update(last_run_at=None)
>>> PeriodicTasks.update_changed()

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:

>>> 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:

>>> 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

There’s also a “choices tuple” available should you need to present this to the user:

>>> IntervalSchedule.PERIOD_CHOICES

Now that we have defined the schedule object, we can create the periodic task entry:

>>> 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:

>>> 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)
... )

Example creating crontab-based periodic task

A crontab schedule has the fields: minute, hour, day_of_week, day_of_month and month_of_year, so if you want the equivalent of a 30 * * * * (execute 30 minutes past every hour) crontab entry you specify:

>>> from django_celery_beat.models import CrontabSchedule, PeriodicTask
>>> schedule, _ = CrontabSchedule.objects.get_or_create(
...     minute='30',
...     hour='*',
...     day_of_week='*',
...     day_of_month='*',
...     month_of_year='*',
...     timezone=zoneinfo.ZoneInfo('Canada/Pacific')
... )

The crontab schedule is linked to a specific timezone using the ‘timezone’ input parameter.

Then to create a periodic task using this schedule, use the same approach as the interval-based periodic task earlier in this document, but instead of interval=schedule, specify crontab=schedule:

>>> PeriodicTask.objects.create(
...     crontab=schedule,
...     name='Importing contacts',
...     task='proj.tasks.import_contacts',
... )

Temporarily disable a periodic task

You can use the enabled flag to temporarily disable a periodic task:

>>> periodic_task.enabled = False
>>> periodic_task.save()

Example running periodic tasks

The periodic tasks still need ‘workers’ to execute them. So make sure the default Celery package is installed. (If not installed, please follow the installation instructions here: https://github.com/celery/celery)

Both the worker and beat services need to be running at the same time.

  1. Start a Celery worker service (specify your Django project name):

    $ celery -A [project-name] worker --loglevel=info
  2. As a separate process, start the beat service (specify the Django scheduler):

    $ celery -A [project-name] beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler

    OR you can use the -S (scheduler flag), for more options see celery beat --help):

    $ celery -A [project-name] beat -l info -S django

    Also, as an alternative, you can run the two steps above (worker and beat services) with only one command (recommended for development environment only):

    $ celery -A [project-name] worker --beat --scheduler django --loglevel=info
  3. Now you can add and manage your periodic tasks from the Django Admin interface.

Installation

You can install django-celery-beat-next either via the Python Package Index (PyPI) or from source.

To install using pip:

$ pip install --upgrade django-celery-beat-next

Downloading and installing from source

Download the latest version of django-celery-beat-next from https://pypi.org/project/django-celery-beat-next/

You can install it by doing the following :

$ python3 -m venv .venv
$ source .venv/bin/activate
$ pip install --upgrade build pip
$ tar xvfz django-celery-beat-next-0.0.0.tar.gz
$ cd django-celery-beat-next-0.0.0
$ python -m build
$ pip install --upgrade .

After installation, add django_celery_beat to Django’s settings module:

INSTALLED_APPS = [
    ...,
    'django_celery_beat',
]

Run the django_celery_beat migrations using:

$ python manage.py migrate django_celery_beat

Using the development version

With pip

You can install the latest main version of django-celery-beat-next using the following pip command:

$ pip install git+https://github.com/azataiot/django-celery-beat-next.git#egg=django-celery-beat-next

Developing django-celery-beat

To spin up a local development copy of django-celery-beat with Django admin at http://127.0.0.1:58000/admin/ run:

$ docker-compose up --build

Log-in as user admin with password admin.

TZ Awareness:

If you have a project that is time zone naive, you can set DJANGO_CELERY_BEAT_TZ_AWARE=False in your settings file.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_celery_beat_next-2.10.0.tar.gz (180.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_celery_beat_next-2.10.0-py3-none-any.whl (105.8 kB view details)

Uploaded Python 3

File details

Details for the file django_celery_beat_next-2.10.0.tar.gz.

File metadata

  • Download URL: django_celery_beat_next-2.10.0.tar.gz
  • Upload date:
  • Size: 180.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for django_celery_beat_next-2.10.0.tar.gz
Algorithm Hash digest
SHA256 1ed8ce607fd4ea6ac6af6ecc9cba9045a1a4ad5ce3587aa6a41cc566be3b306f
MD5 1a0a4db612374ed61b6a3627dc3b81b8
BLAKE2b-256 0a0a8d4aa1bb02ad14ac78dcf710a6b7ddd92aeaded7d5bfae3990fe15061428

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_celery_beat_next-2.10.0.tar.gz:

Publisher: build.yml on azataiot/django-celery-beat-next

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_celery_beat_next-2.10.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_celery_beat_next-2.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b7fcd69110a9facbe94d7b87fec699a476015d6ecbb42d6ce4723475c8f348c
MD5 3caeb578efeaf58e9bc2fd697473eb69
BLAKE2b-256 a07569f4782f476cae94b6125056b22a1367afc033e471aa3426d4f193ddb412

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_celery_beat_next-2.10.0-py3-none-any.whl:

Publisher: build.yml on azataiot/django-celery-beat-next

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

2.10.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page