Has anyone succeeded in using celery with pylons

為{幸葍}努か 提交于 2019-12-23 13:25:52

问题


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 standalone project and using celery-pylons, both without much success.. :(

Thanks in advance for your help.


回答1:


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.




回答2:


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/



来源:https://stackoverflow.com/questions/3989366/has-anyone-succeeded-in-using-celery-with-pylons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!