0Pricing
Django Academy · Lektion

Geplante Jobs mit Celery Beat

Regelmäßige Aufgaben nach einem Zeitplan ausführen

Geplante Jobs mit Celery Beat ist eine kostenlose Django Academy-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Django Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Django Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

Beyond One-Off Tasks

So far tasks run when you queue them. But some jobs should run on a clock: nightly reports, hourly cleanups, weekly digests. That is where Beat comes in. ⏰

What Celery Beat Is

Celery Beat is a scheduler. It is a separate process that wakes up on time and drops scheduled tasks onto the same queue your workers read.

Beat Plus Worker

Beat only queues jobs on schedule; it never runs them itself. You still need a worker running to actually execute what Beat enqueues.

Install the Scheduler

The django-celery-beat package stores your schedule in the database, so you can even edit it from the admin later. Install it first.

pip install django-celery-beat

Define a Beat Schedule

In settings, CELERY_BEAT_SCHEDULE is a dict mapping a name to a task path and how often to run it.

CELERY_BEAT_SCHEDULE = {
    "daily-report": {
        "task": "reports.tasks.send_report",
        "schedule": 86400.0,
    },
}

Intervals in Seconds

A plain number means "every N seconds". So 86400.0 is once a day and 3600.0 is once an hour. Simple, but a bit rigid for real calendars.

Crontab for Real Calendars

For "8am every Monday" use a crontab schedule. It reads like a cron line and handles days, hours, and minutes precisely.

from celery.schedules import crontab
schedule = crontab(hour=8, minute=0, day_of_week=1)

Wire Crontab In

Drop a crontab object straight into the schedule value to control exactly when a task fires.

"weekly-digest": {
    "task": "news.tasks.digest",
    "schedule": crontab(hour=8, minute=0, day_of_week="mon"),
}

Run the Beat Process

Start Beat in its own terminal, beside the worker. Now you have three processes: web server, worker, and the beat scheduler.

celery -A myproject beat -l info

Avoid Duplicate Beats

Run only one Beat process. Two schedulers means every job fires twice, which can double-send emails or double-bill users. 🚫

Edit Schedules from Admin

With django-celery-beat, schedules live in the database, so non-developers can add or pause periodic tasks right from the Django admin.

Quick Check

What is the relationship between Celery Beat and the worker?

Recap: Scheduled Jobs

Celery Beat queues tasks on a schedule using intervals or crontab. Run exactly one Beat plus a worker, and edit schedules from the admin. 🗓️

Häufig gestellte Fragen

Ist die Lektion „Geplante Jobs mit Celery Beat“ kostenlos?

Ja — der vollständige Text von „Geplante Jobs mit Celery Beat“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Django Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Django Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Geplante Jobs mit Celery Beat“?

Regelmäßige Aufgaben nach einem Zeitplan ausführen Du übst Django Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Django Academy zu starten?

Keine Vorkenntnisse erforderlich. Django Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.

Wie lange dauert die Lektion „Geplante Jobs mit Celery Beat“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Django Academy-Lektion Code schreiben und ausführen?

Ja. Jede Django Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Warum Sie Background Tasks benötigen
  2. Celery mit einem Broker einrichten
  3. @shared_task schreiben und aufrufen
  4. Geplante Jobs mit Celery Beat
← Zurück zu Django Academy