Skip to main content

A Celery Beat scheduler that stores the schedule in MongoDB.

Project description

Celery-MongoBeat

A modern, drop-in replacement for celerybeat-mongo. This project provides a Celery Beat scheduler that stores and retrieves task schedules from a MongoDB collection, allowing for dynamic management of periodic tasks without restarting the Celery Beat service.

Why celery-mongobeat?

The original celerybeat-mongo library is no longer actively maintained and contains several critical bugs. This project was created to provide a stable, reliable, and modern alternative for the community, ensuring continued support for dynamic, database-backed Celery schedules.

Features

  • Stable and Reliable: Fixes critical bugs from celerybeat-mongo, such as the issue where disabling one task would prevent all tasks from running.
  • Dynamic Task Management: Add, modify, and remove periodic tasks on the fly without restarting the beat service.
  • MongoDB Backend: Leverages MongoDB for a robust and scalable schedule store.
  • Fine-Grained Control:
    • Run Count Limiting: Use max_run_count to run a task a specific number of times and then automatically disable it.
  • Flexible Configuration: Full support for advanced pymongo.MongoClient options (like SSL) via mongodb_scheduler_client_kwargs.
  • Backwards Compatible: Supports legacy configuration variables from celerybeat-mongo for a smoother transition.
  • Modern Tooling: Built with a modern Python packaging structure (pyproject.toml).
  • All Schedule Types: Natively supports interval, crontab, and solar schedules.

Installation

Install the package from PyPI:

pip install celery-mongobeat

Configuration

To use this scheduler, set the beat_scheduler option in your Celery configuration.

Recommended Configuration

# celeryconfig.py

mongodb_scheduler_url = "mongodb://localhost:27017/"
mongodb_scheduler_db = "celery"
mongodb_scheduler_collection = "schedules"

beat_scheduler = "celery_mongobeat.beat:MongoScheduler"

Migrating from celerybeat-mongo

celery-mongobeat is designed as a near drop-in replacement, but there is one important configuration change you must make when migrating:

  • Update the Scheduler Path: The import path for the scheduler has been updated to align with modern package structures and Celery best practices.

You must change your beat_scheduler setting from: 'celerybeat_mongo.schedulers.MongoScheduler' (the old path) to: 'celery_mongobeat.beat:MongoScheduler' (the new path)


### Legacy (Backwards-Compatible) Configuration

If you are migrating from `celerybeat-mongo`, this library provides backward compatibility for the uppercase configuration variables. Modern, lowercase settings (e.g., `mongodb_scheduler_url`) will always take precedence.

```python
# celeryconfig.py

# Legacy uppercase individual settings (from celerybeat-mongo)
CELERY_MONGODB_SCHEDULER_URL = "mongodb://localhost:27017/"
CELERY_MONGODB_SCHEDULER_DB = "celery"
CELERY_MONGODB_SCHEDULER_COLLECTION = "schedules"

beat_scheduler = "celery_mongobeat.beat:MongoScheduler"

Usage

Once configured, start Celery Beat as you normally would:

celery -A your_app beat -l info

You can now manage your schedules by adding, updating, or removing documents in the configured MongoDB collection.

Programmatic Usage Example

For users who prefer a programmatic API over manually inserting documents into MongoDB, celery-mongobeat provides a convenient ScheduleManager helper class.

This allows you to easily create, update, and disable tasks from within your application code.

Example Usage

# In your application's setup code
from pymongo import MongoClient
from celery_mongobeat.helpers import ScheduleManager

client = MongoClient("mongodb://localhost:27017/")
db = client["celery"]
schedules_collection = db["schedules"]  # Must match your celery-mongobeat config

manager = ScheduleManager(schedules_collection)

# Example: Create a task to run every 30 seconds
manager.create_interval_task(
    name='my-periodic-task',
    task='your_project.tasks.some_task',
    every=30,
    period='seconds',
    args=[1, 2, 3]
)
print("Upserted interval task: 'my-periodic-task'")

# Example: Create a task that runs 5 times and then stops
manager.create_interval_task(
    name='run-five-times-task',
    task='your_project.tasks.some_task',
    every=60,
    period='seconds',
    max_run_count=5
)
print("Upserted limited-run task: 'run-five-times-task'")

# Example: Disable a task
manager.disable_task('my-periodic-task')
print("Disabled task: 'my-periodic-task'")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

celery_mongobeat-0.1.6.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

celery_mongobeat-0.1.6-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file celery_mongobeat-0.1.6.tar.gz.

File metadata

  • Download URL: celery_mongobeat-0.1.6.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for celery_mongobeat-0.1.6.tar.gz
Algorithm Hash digest
SHA256 8f74ce6767f6299bedb89c884533b97de18dc2fd2ed2149cd8188476ce15e5e8
MD5 73644f344236f327b2fae035d298c50e
BLAKE2b-256 b8b3623692696096ad319bba75d4ecd01fc6eebcf8dc1323f6c253c6340b8da4

See more details on using hashes here.

Provenance

The following attestation bundles were made for celery_mongobeat-0.1.6.tar.gz:

Publisher: publish.yml on sockmysox/celery-mongobeat

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file celery_mongobeat-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for celery_mongobeat-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 30a013ef47401267921650b191c4484622ec7fd2d06b588bd74be66cca5cf0c6
MD5 94eafe66f624eb34d422c506b73e9c51
BLAKE2b-256 050a9c96eb987f749afd0217b8b2fc05110e736062bce056d65bd1e6897a98ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for celery_mongobeat-0.1.6-py3-none-any.whl:

Publisher: publish.yml on sockmysox/celery-mongobeat

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page