Skip to main content

A Celery Beat Scheduler that uses MongoDB to store both schedule definitions and status information

Project description

celerybeat-mongo2

PyPI version

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

celerybeat_mongo2-0.2.2.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

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

celerybeat_mongo2-0.2.2-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file celerybeat_mongo2-0.2.2.tar.gz.

File metadata

  • Download URL: celerybeat_mongo2-0.2.2.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

Hashes for celerybeat_mongo2-0.2.2.tar.gz
Algorithm Hash digest
SHA256 d588b2cac68088b7e7a7b72a38298c7f02316b755bf4d609c789f7c0956be42d
MD5 93f568db3ac796745dd1fe7b736ad49f
BLAKE2b-256 ad19caddc423a347fd1518066add5a17540469e1969584ba62e5f552f66db3f1

See more details on using hashes here.

File details

Details for the file celerybeat_mongo2-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for celerybeat_mongo2-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 44e5403b790e01bb7e3054de56eb26220a3aacb11564259f8e825c25d805ea3d
MD5 ae107b45c711da2539dc8da8f4c3f8d8
BLAKE2b-256 668d039ba76627a1d6cf4440745bd2f01b0535daf7c259fd79fd66439b127860

See more details on using hashes here.

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