0Pricing
Django Academy · Aula

Tarefas agendadas com Celery Beat

Execute tarefas periódicas conforme uma programação

Tarefas agendadas com Celery Beat é uma aula grátis de Django Academy no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Django Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Django Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

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. 🗓️

Perguntas Frequentes

A aula “Tarefas agendadas com Celery Beat” é grátis?

Sim — o texto completo de “Tarefas agendadas com Celery Beat” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Django Academy, atualize para CoddyKit PRO. O curso de Django Academy inclui 4 aulas no total.

O que vou aprender em “Tarefas agendadas com Celery Beat”?

Execute tarefas periódicas conforme uma programação Você pratica Django Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Django Academy?

Nenhuma experiência prévia é necessária. Django Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “Tarefas agendadas com Celery Beat”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Django Academy?

Sim. Cada aula de Django Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Por que você precisa de tarefas em segundo plano
  2. Configurando Celery com um intermediário
  3. Escrevendo e chamando @shared_task
  4. Tarefas agendadas com Celery Beat
← Voltar para Django Academy