开发者

Has anyone succeeded in using celery with pylons

开发者 https://www.devze.com 2023-01-21 22:00 出处:网络
I have a pylons based webapp and i\'d love to use celery + rabbitmq for some time taking tasks. I\'ve taken a look at the celery-pylons project but I haven\'t succeeded in using it.

I have a pylons based webapp and i'd love to use celery + rabbitmq for some time taking tasks. I've taken a look at the celery-pylons project but I haven't succeeded in using it.

My main problem with celery is: where do i put the celeryconfig.py file or is there any other way to specify the celery options eg. BROKER_HOST and the like, from within a pylons app (In the same way one can put the options in the django settings.py file when using django-celery).

Basically, i investigated 2 options: using celery as a standalo开发者_运维百科ne project and using celery-pylons, both without much success.. :(

Thanks in advance for your help.


I am doing this currently, although I've not updated celery in some time. I'm still on 2.0.0 I think.

What I did was to create a celery_app directory within my pylons application. (so in same directory as data, controllers, etc.)

In that directory are my celeryconfig.py, tasks.py, and pylons_tasks.py.

pylons_tasks.py is just a file that initializes the pylons application so I can load Pylons models and such into the celery tasks.py file. So it does the pylons init and then imports tasks.py.

The celeryconfig is then set to use myapp.celery_app.pylons_tasks as the CELERY_IMPORTS value.

CELERY_IMPORTS = ("myapp.celery_app.pylons_tasks", )

Hope that helps some.


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 https://bitbucket.org/dougtabuchi/celery-pylons/src 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.

A good pylons project to look at that uses celery is https://rhodecode.org/rhodecode/files/tip/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号