芹菜,postgresql->配置后端

2024-06-13 02:27:44 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我刚开始吃芹菜,试着做一些简单的测试来感受一下。 我试图设置一个芹菜使用postgres作为我的后端。 在本页:
http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html#keeping-results 我看到了例子

celery = Celery('tasks', backend='redis://localhost', broker='amqp://')

所以在我的代码中我尝试

celery = Celery('tasks', 
               backend='sqla+postgresql://celery_exp:celery_exp@myhost/celery_exp',
                broker='sqla+postgresql://celery_exp:celery_exp@myhost/celery_exp',)

但我在启动它的时候总是遇到这个错误:

ImportError: No module named sqla+postgresql

在文档中,我尝试了不同的变体,比如

postgresql://  
postgresql+psycopg2://  

我知道连接字符串是正确的,因为在芹菜构造函数中取出后端参数可以按预期工作。
我在这里做错什么了?我觉得一定是什么蠢事,因为我在网上什么也找不到。

提前谢谢。


Tags: orgbackendhttpdocspostgresqlpostgresbrokeren
2条回答

答案就在这里http://celery.readthedocs.org/en/latest/configuration.html#database-url-examples

您需要用db+作为常规SQL炼金术url字符串的前缀,例如

CELERY_RESULT_BACKEND = "db+postgresql+psycopg2://..."

芹菜获取您传递它的URL,查看前缀(在本例中为“sqla+postgresql”),并查找与之匹配的后端。没有“通用”只使用数据库加载后端。您可以检查系统上芹菜文件夹中的backend/init.py以查看整个别名字典,然后添加自己的字典。

相关问题 更多 >