__init__.py 581 Bytes
Newer Older
kaiyou's avatar
kaiyou committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
import celery
import yaml
import os

from amonit import scheduler


def schedule(sender, **kwargs):
    sender.scheduler.schedule(sender)


def main(config=None):
    # Load the configuration
    if not config:
        with open(os.environ.get("AMONIT_CONFIG", "amonit.yaml")) as handle:
            config = yaml.load(handle)
    # Create and initialize the celery app
    app = celery.Celery('amonit', broker=config["general"]["broker"])
    app.config = config
    app.scheduler = scheduler.Scheduler(config)
    app.on_after_configure.connect(schedule)
    return app


main()