Using Celery with Pylons
I am trying to set up celery and pylons and can't seem to get it working. I downloaded pylons-celery, but how do I poin开发者_如何学Ct my Pylons environment to where the celeryconfig.py is? I placed the config file in my pylons-app\celery folder. I read this post, but it doesn't mention how to pair celery with pylons.. Any pointers are appreciated - thanks!
The tightest integration with pylons is to build a custom loader into paste commands. This is what celery-pylons does. Check out my fork of celery-pylons which should work with the latest celery and pylons 1.0.
To get the celeryd side working you need to add the correct options in your ini file and then call paster celeryd development.ini
For the webapp side you just need to import celerypylons
in environment.py Then you will be able to import and use your tasks from anywhere in your project.
I'm not exactly sure what you're trying to achieve, but I'll explain how I just setup Pylons to work with celery and hopefully you can gain something from it.
My setup is fairly simple. I implemented a REST API with Pylons using a single controller called jobs. When a POST request is received, the controller action would submit a new task to celery, capture the new tasks's uuid, and respond to the original request with the uuid. I originally place my celeryconfig.py file in my controllers directory, but once I deployed the pylons app egg to the apache web server, the celeryconfig.py was no longer automatically found.
To remedy this, I created a celery directory at the same level as the model and controllers directories, and I placed my celeryconfig.py file there, along with an empty init.py.
Here is a snippet of code from jobs controller where I connect to celery and submit a new task.
from celery import Celery
from my_pylons_app.celery import celeryconfig
celery_app = Celery()
celery_app.config_from_object(celeryconfig)
result = celery_app.send_task("process_job", [job_guid], connect_timeout=10)
I was able to get this working with both my internal paste web server and my public live apache2 web server.
精彩评论