mongodb - Working example of celery with mongo DB -
i'm new celery, , working on running asynchronous tasks using celery.
- i want save results of tasks mongodb.
- i want use amqp broker.
celery project examples didn't me much. can point me working examples?
to use mongodb backend store have explicitly configure celery use mongodb backend.
http://docs.celeryproject.org/en/latest/getting-started/brokers/mongodb.html#broker-mongodb
as said documentation not show complete working example. started playing celery have been using mongodb. created short working tutorial using mongodb , celery http://skillachie.com/?p=953
however these snippets should contain need hello world going celery , mongodb
celeryconfig.py
celery.schedules import crontab celery_result_backend = "mongodb" celery_mongodb_backend_settings = { "host": "127.0.0.1", "port": 27017, "database": "jobs", "taskmeta_collection": "stock_taskmeta_collection", } #used schedule tasks periodically , passing optional arguments #can useful. celery not seem support scheduled task periodic celerybeat_schedule = { 'every-minute': { 'task': 'tasks.add', 'schedule': crontab(minute='*/1'), 'args': (1,2), }, }
tasks.py
from celery import celery import time #specify mongodb host , datababse connect broker_url = 'mongodb://localhost:27017/jobs' celery = celery('eod_tasks',broker=broker_url) #loads settings backend store results of jobs celery.config_from_object('celeryconfig') @celery.task def add(x, y): time.sleep(30) return x + y
Comments
Post a Comment