问题描述
我有一个基于塔的Web应用程序,我很想在一段时间内使用芹菜+ Rabbitmq.我看过celery-pylons项目,但没有成功使用它.
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.
我对celery的主要问题是:我在哪里放置celeryconfig.py文件,或者是否有其他方法可以指定celery选项,例如.从pylons应用程序中获取BROKER_HOST之类的东西(使用django-celery时,也可以将选项放入django settings.py文件中.)
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).
基本上,我研究了2种选择:将celery用作独立项目和使用celery-pylons,但这两种方法都没有太大的成功..:(
Basically, i investigated 2 options: using celery as a standalone project and using celery-pylons, both without much success.. :(
预先感谢您的帮助.
推荐答案
我目前正在这样做,尽管我已经有一段时间没有更新芹菜了.我认为我仍在使用2.0.0.
I am doing this currently, although I've not updated celery in some time. I'm still on 2.0.0 I think.
我所做的是在pylons应用程序中创建一个celery_app目录. (因此与数据,控制器等位于同一目录中)
What I did was to create a celery_app directory within my pylons application. (so in same directory as data, controllers, etc.)
在该目录中是我的celeryconfig.py,tasks.py和pylons_tasks.py.
In that directory are my celeryconfig.py, tasks.py, and pylons_tasks.py.
pylons_tasks.py只是一个初始化pylons应用程序的文件,因此我可以将Pylons模型等加载到celery task.py文件中.因此,它会进行挂架初始化,然后导入task.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.
然后将celeryconfig设置为使用myapp.celery_app.pylons_tasks作为CELERY_IMPORTS值.
The celeryconfig is then set to use myapp.celery_app.pylons_tasks as the CELERY_IMPORTS value.
CELERY_IMPORTS = ("myapp.celery_app.pylons_tasks", )
希望对某些人有帮助.
这篇关于有没有人成功地将芹菜和塔一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!