Celery Beatによる定期ジョブ
スケジュールに従って定期タスクを実行します
「Celery Beatによる定期ジョブ」はCoddyKit上の無料Django Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDjango Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Django Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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-beatDefine 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 infoAvoid 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. 🗓️
よくある質問
「Celery Beatによる定期ジョブ」レッスンは無料ですか?
はい。「Celery Beatによる定期ジョブ」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Django Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Django Academyコースには全4レッスンが含まれています。
「Celery Beatによる定期ジョブ」で何を学びますか?
スケジュールに従って定期タスクを実行します ブラウザで直接実行するハンズオンコードでDjango Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Django Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのDjango Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「Celery Beatによる定期ジョブ」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このDjango Academyレッスンでコードを書いて実行できますか?
はい。すべてのDjango Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Background Tasksが必要な理由
- Brokerを使ったCeleryの設定
- @shared_taskの作成と呼び出し
- Celery Beatによる定期ジョブ