A Celery Beat Scheduler that uses MongoDB to store both schedule definitions and status information
Project description
celerybeat-mongo2
A maintained fork of zmap/celerybeat-mongo, which has been archived upstream.
This is a Celery Beat Scheduler that stores both the schedules themselves and their status information in a backend Mongo database. It can be installed by installing the celerybeat-mongo2 Python egg:
# pip install celerybeat-mongo2
And specifying the scheduler when running Celery Beat, e.g.:
$ celery -A myproj beat -S celerybeatmongo.schedulers.MongoScheduler
Settings
The settings for the scheduler are defined in your celery configuration file similar to how other aspects of Celery are configured:
mongodb_scheduler_url: The mongodb url connection used to store schedules.
mongodb_scheduler_db: The Mongodb database name
mongodb_scheduler_collection (optional): the collection name used by model. If no value are specified, the default value will be used: schedules.
Usage
Celerybeat-mongo supports Interval, Crontab and Solar schedules. Schedules easily can be manipulated using the mongoengine models in celerybeatmongo.models module.
Example creating interval-based periodic task
To create a periodic task executing at an interval you must first create the interval object:
from celery import Celery
from celerybeatmongo import PeriodicTask, connect_from_app
app = Celery("hello")
app.conf.update(
mongodb_scheduler_db="my_project",
mongodb_scheduler_url="mongodb://localhost:27017",
)
connect_from_app(app)
periodic = PeriodicTask(
name='Importing contacts',
task="proj.import_contacts",
schedule=PeriodicTask.Interval(every=10, period="seconds"),
)
periodic.save()
Example creating crontab periodic task
A crontab schedule has the fields: minute, hour, day_of_week, day_of_month and month_of_year, so if you want the equivalent of a 30 7 * * 1 (Executes every Monday morning at 7:30 a.m) crontab entry you specify:
from celery import Celery
from celerybeatmongo import PeriodicTask, connect_from_app
app = Celery("hello")
app.conf.update(
mongodb_scheduler_db="my_project",
mongodb_scheduler_url="mongodb://localhost:27017",
)
connect_from_app(app)
periodic = PeriodicTask(name="Send Email Notification", task="proj.notify_customers")
periodic.schedule = PeriodicTask.Crontab(minute="30", hour="7", day_of_week="1",
day_of_month="*", month_of_year="*")
periodic.save()
Example creating solar periodic task
A solar schedule fires at a solar event (sunrise, sunset, etc.) at a given latitude/longitude. For example, to send a morning briefing at sunrise in London:
from celery import Celery
from celerybeatmongo import PeriodicTask, connect_from_app
app = Celery("hello")
app.conf.update(
mongodb_scheduler_db="my_project",
mongodb_scheduler_url="mongodb://localhost:27017",
)
connect_from_app(app)
periodic = PeriodicTask(name="Morning briefing", task="proj.send_briefing")
periodic.schedule = PeriodicTask.Solar(
event="sunrise",
latitude=51.5074,
longitude=-0.1278,
)
periodic.save()
Supported events: dawn_astronomical, dawn_nautical, dawn_civil, sunrise, solar_noon, sunset, dusk_civil, dusk_nautical, dusk_astronomical.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file celerybeat_mongo2-1.0.0.tar.gz.
File metadata
- Download URL: celerybeat_mongo2-1.0.0.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35ceb13e8584cbe2dbd08470f667b43e1279a41f496887182370fc4b1aca469d
|
|
| MD5 |
87056afdcd9eb175b5f259c1468f3851
|
|
| BLAKE2b-256 |
ef751001b4f7be7067f4f3ca9bedd897c04948e8ae2b8936070aacffec8c0196
|
File details
Details for the file celerybeat_mongo2-1.0.0-py3-none-any.whl.
File metadata
- Download URL: celerybeat_mongo2-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fda85c7c29acf2bc8746e06599cf3840b2ba501f81a221c97f5d6acd9f51442
|
|
| MD5 |
387f48f8cc604cc21d4e45a16c3e4e4c
|
|
| BLAKE2b-256 |
9f2cf9b2bc3355303dafb940beccfd5f0ba8f27491d578861142ace38ae6bdf6
|