Code Monkey home page Code Monkey logo

celerybeat-mongo's Introduction

celerybeat-mongo

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-mongo Python egg:

# pip install celerybeat-mongo

And specifying the scheduler when running Celery Beat, e.g.:

$ celery 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 task results.
  • 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 just supports Interval and Crontab schedules. Schedules easily can be manipulated using the mongoengine models in celerybeat mongo.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

config = {
    "mongodb_scheduler_db": "my_project",
    "mongodb_scheduler_url": "mongodb://localhost:27017",
}

app = Celery('hello', broker='redis://localhost//')
app.conf.update(**config)

from celerybeatmongo.models import PeriodicTask, Interval

periodic = PeriodicTask(
    name='Importing contacts',
    task="proj.import_contacts"
    interval=Interval(every=10, period="seconds") # executes every 10 seconds.
)
periodic.save()

Note

You should import celerybeat-mongo just after celery initialization.

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

config = {
    "mongodb_scheduler_db": "my_project",
    "mongodb_scheduler_url": "mongodb://localhost:27017",
}

app = Celery('hello', broker='redis://localhost//')
app.conf.update(**config)

from celerybeatmongo.models import PeriodicTask, Crontab

periodic = PeriodicTask(name="Send Email Notification", task="proj.notify_customers")
periodic.crontab = Crontab(minute="30", hour="7", day_of_week="1",
                           day_of_month="0", month_of_year="*")
periodic.save()

celerybeat-mongo's People

Contributors

zakird avatar noirbizarre avatar dimrozakis avatar kjlockhart avatar usrlocalben avatar johnnywalnut avatar dongsheng2014 avatar gmiejski avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.