Sobes.tech
Junior — Middle

What is the purpose of the Celery Beat component in a task queue system?

sobes.tech AI

Answer from AI

The Celery Beat component is used for scheduling periodic tasks in the Celery queue system. It functions as a scheduler that sends tasks to the Celery queue according to a schedule for execution.

Main functions of Celery Beat:

  • Allows tasks to be run on a schedule (e.g., every hour, daily, on specific days of the week).
  • Stores the task schedule (can use a file, database, or other storage).
  • Automatically sends tasks to the Celery queue at the right time.

Example usage:

from celery import Celery
from celery.schedules import crontab

app = Celery('tasks', broker='redis://localhost')

app.conf.beat_schedule = {
    'task-every-minute': {
        'task': 'myapp.tasks.my_task',
        'schedule': crontab(minute='*/1'),
    },
}

@app.task
def my_task():
    print('Task executed')

Here, Celery Beat will run my_task every minute, sending it to the queue for execution.