{"id":2888,"library":"celery-redbeat","title":"Celery RedBeat","description":"Celery RedBeat is a custom Celery Beat Scheduler that leverages Redis for persistent storage of scheduled tasks and their runtime metadata. It allows for dynamic creation, modification, and deletion of periodic tasks at runtime without requiring a restart of the Celery Beat service. This design provides fast startup times, even with a large number of tasks, and prevents multiple Beat instances from running simultaneously through a distributed lock mechanism. The current version is 2.3.3, and it maintains an active development and release cadence.","status":"active","version":"2.3.3","language":"en","source_language":"en","source_url":"https://github.com/sibson/redbeat","tags":["celery","redis","scheduler","task queue","beat","dynamic scheduling"],"install":[{"cmd":"pip install celery-redbeat","lang":"bash","label":"Install Celery RedBeat"}],"dependencies":[{"reason":"RedBeat is a scheduler for Celery and requires a Celery application to function.","package":"celery"},{"reason":"RedBeat uses Redis as its backend for storing schedule data.","package":"redis"}],"imports":[{"note":"The `RedBeatScheduler` class is located within the `redbeat.schedulers` module, not directly under `redbeat`.","wrong":"from redbeat import RedBeatScheduler","symbol":"RedBeatScheduler","correct":"from redbeat.schedulers import RedBeatScheduler"},{"symbol":"RedBeatSchedulerEntry","correct":"from redbeat import RedBeatSchedulerEntry"}],"quickstart":{"code":"import os\nfrom celery import Celery\nfrom celery.schedules import crontab\nfrom redbeat import RedBeatSchedulerEntry\n\n# Configure Celery app with RedBeat\napp = Celery('my_app', broker=os.environ.get('CELERY_BROKER_URL', 'redis://localhost:6379/0'))\napp.conf.update(\n    redbeat_redis_url=os.environ.get('REDBEAT_REDIS_URL', 'redis://localhost:6379/1'), # Use a different DB than broker\n    redbeat_lock_timeout=300, # 5 minutes\n    timezone='UTC',\n    enable_utc=True,\n    # Other Celery settings\n)\n\n# Define a Celery task\n@app.task\ndef my_periodic_task(arg1, arg2):\n    print(f\"Executing task with {arg1} and {arg2}\")\n    return arg1 + arg2\n\n# Example of dynamically scheduling a task\n# This code would typically run in an application context, not directly in the Beat process\n# To make it runnable for quickstart, wrap it in a function\ndef schedule_task():\n    # Ensure RedBeat is properly configured and Redis is running\n    # A new entry for an interval task\n    entry_interval = RedBeatSchedulerEntry(\n        'my-interval-task',\n        'my_app.my_periodic_task', # Task path\n        app.conf.beat_schedule.schedule(run_every=10), # Run every 10 seconds\n        args=[10, 20],\n        kwargs={'some_kwarg': 'value'},\n        app=app\n    )\n    entry_interval.save()\n    print(f\"Scheduled interval task: {entry_interval.key}\")\n\n    # A new entry for a crontab task (every minute)\n    entry_crontab = RedBeatSchedulerEntry(\n        'my-crontab-task',\n        'my_app.my_periodic_task', # Task path\n        crontab(minute='*', hour='*', day_of_week='*'), # Run every minute\n        args=['hello', 'world'],\n        app=app\n    )\n    entry_crontab.save()\n    print(f\"Scheduled crontab task: {entry_crontab.key}\")\n\n# To run Celery Beat with RedBeat:\n# celery -A my_app beat -S redbeat.RedBeatScheduler --loglevel=info\n\n# To run Celery Worker:\n# celery -A my_app worker --loglevel=info\n\n# Example of how to call schedule_task() (for demonstration purposes)\nif __name__ == '__main__':\n    # In a real application, you'd trigger this via API or startup logic\n    # For this quickstart, we'll just demonstrate saving an entry\n    # and assume you'll run Beat and Worker separately.\n    print(\"To run, ensure Redis is active, then execute:\")\n    print(\"1. For Celery Beat: celery -A my_app beat -S redbeat.RedBeatScheduler --loglevel=info\")\n    print(\"2. For Celery Worker: celery -A my_app worker --loglevel=info\")\n    print(\"3. Then, from an interactive shell or a script, call schedule_task()\")\n    # Example of manual scheduling if app context is setup:\n    # from my_app import app, my_periodic_task, schedule_task\n    # schedule_task()\n\n","lang":"python","description":"To get started, configure your Celery application to use `RedBeatScheduler` by setting `redbeat_redis_url` and specifying the scheduler when running `celery beat`. Tasks can be defined dynamically using `RedBeatSchedulerEntry` instances and saved to Redis. It's recommended to use a different Redis database for RedBeat than for your Celery broker."},"warnings":[{"fix":"Upgrade your Python environment to 3.8 or newer, or pin `celery-redbeat` to a version prior to 2.1.0.","message":"Version 2.1.0 dropped support for Python versions older than 3.8. Ensure your Python environment meets this requirement before upgrading.","severity":"breaking","affected_versions":"<2.1.0"},{"fix":"Refer to the `celery-redbeat` documentation for version 0.10.0+ to adjust task definitions and scheduler configurations.","message":"Version 0.10.0 introduced significant API changes, including breaking changes due to a reworked API and improved Python 3 compatibility. Users upgrading from very old versions (pre-0.10.0) may need to update their task definitions and configurations.","severity":"breaking","affected_versions":"<0.10.0"},{"fix":"Ensure `redbeat_lock_key` is not `None` in production environments. Configure `redbeat_lock_timeout` appropriately (e.g., 5 times `CELERYBEAT_MAX_LOOP_INTERVAL`) for your application's recovery needs. Monitor Redis for lock key health.","message":"RedBeat uses a distributed lock to prevent multiple Beat instances from running simultaneously. Misconfiguration of `redbeat_lock_key` or `redbeat_lock_timeout` can lead to multiple Beat instances (if `redbeat_lock_key` is `None`) or extended downtime if a Beat instance fails and the lock takes too long to expire.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always configure `redbeat_redis_url` to point to a different Redis database (e.g., `redis://localhost:6379/1`) than your Celery broker/result backend (e.g., `redis://localhost:6379/0`).","message":"Using the same Redis database for Celery's broker/result backend and RedBeat's schedule storage can lead to issues, particularly if idle connections are closed, potentially corrupting the scheduler state and causing tasks to stop running silently.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Run Celery Beat and Celery Workers as separate processes. Monitor Celery worker queues and task execution times. Implement robust logging and monitoring for both Celery Beat and Redis connections. Consider clearing Redis keys and recreating tasks if the scheduler gets into a corrupted state.","message":"Celery Beat, including RedBeat, can sometimes silently stop dispatching tasks or fail to pick up new tasks, especially if workers are saturated with long-running tasks, if there are underlying Redis connection issues, or if Beat and Worker are run in the same process (which is not recommended for production).","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}