我正在使用Pyramid-1.2.1创建Web应用程序,SQLAlchemy作为数据库后端 现在我需要和这个应用程序一起做一些周期性的任务,我想使用Celery作为任务处理器,SQLAlchemy作为消息队列和结果后端。
1)我已经安装了Celery-2.1.4,但我无法弄清楚如何使它工作。这是我的celeryconfig.py
文件:
# List of modules to import when celery starts.
CELERY_IMPORTS = ("my_app.tasks", )
## Result store settings.
CELERY_RESULT_BACKEND = "database"
CELERY_RESULT_DBURI = "sqlite:///MyDataBase.db"
CELERY_RESULT_SERIALIZER = "json"
## Broker settings.
BROKER_TRANSPORT = "sqlakombu.transport.Transport"
BROKER_HOST = "sqlite:///MyDataBase.db"
my_app.tasks
包含来自芹菜示例的简单添加任务
现在我跑的时候
$ celeryd -l info
我看到以下内容:
[2011-11-11 20:22:50,750: WARNING/MainProcess] celery@OrangeMac.local v2.1.4 is starting.
[2011-11-11 20:22:50,765: WARNING/MainProcess]
Configuration ->
. broker -> sqlakombu.transport.Transport://guest@sqlite:///MyDataBase.db/
. queues ->
. celery -> exchange:celery (direct) binding:celery
. concurrency -> 4
. loader -> celery.loaders.default.Loader
. logfile -> [stderr]@INFO
. events -> OFF
. beat -> OFF
. tasks ->
. chatrooms.task.add
[2011-11-11 20:22:50,787: INFO/PoolWorker-1] child process calling self.run()
[2011-11-11 20:22:50,789: INFO/PoolWorker-2] child process calling self.run()
[2011-11-11 20:22:50,791: INFO/PoolWorker-3] child process calling self.run()
[2011-11-11 20:22:50,796: INFO/PoolWorker-4] child process calling self.run()
[2011-11-11 20:22:50,802: WARNING/MainProcess] celery@OrangeMac.local has started.
[2011-11-11 20:22:50,804: WARNING/MainProcess] Traceback (most recent call last):
[2011-11-11 20:22:50,805: WARNING/MainProcess] File "/Users/shashkin/python_v_env/bin/celeryd", line 8, in <module>
[2011-11-11 20:22:50,805: WARNING/MainProcess] load_entry_point('celery==2.1.4', 'console_scripts', 'celeryd')()
[2011-11-11 20:22:50,805: WARNING/MainProcess] File "/Users/shashkin/python_v_env/lib/python2.7/site-packages/celery-2.1.4-py2.7.egg/celery/bin/celeryd.py", line 166, in main
[2011-11-11 20:22:50,805: WARNING/MainProcess] worker.execute_from_commandline()
[2011-11-11 20:22:50,806: WARNING/MainProcess] File "/Users/shashkin/python_v_env/lib/python2.7/site-packages/celery-2.1.4-py2.7.egg/celery/bin/base.py", line 40, in execute_from_commandline
[2011-11-11 20:22:50,806: WARNING/MainProcess] return self.run(*args, **vars(options))
[2011-11-11 20:22:50,806: WARNING/MainProcess] File "/Users/shashkin/python_v_env/lib/python2.7/site-packages/celery-2.1.4-py2.7.egg/celery/bin/celeryd.py", line 85, in run
[2011-11-11 20:22:50,806: WARNING/MainProcess] return Worker(**kwargs).run()
[2011-11-11 20:22:50,806: WARNING/MainProcess] File "/Users/shashkin/python_v_env/lib/python2.7/site-packages/celery-2.1.4-py2.7.egg/celery/apps/worker.py", line 121, in run
[2011-11-11 20:22:50,807: WARNING/MainProcess] self.run_worker()
[2011-11-11 20:22:50,807: WARNING/MainProcess] File "/Users/shashkin/python_v_env/lib/python2.7/site-packages/celery-2.1.4-py2.7.egg/celery/apps/worker.py", line 219, in run_worker
[2011-11-11 20:22:50,807: WARNING/MainProcess] worker.start()
[2011-11-11 20:22:50,807: WARNING/MainProcess] File "/Users/shashkin/python_v_env/lib/python2.7/site-packages/celery-2.1.4-py2.7.egg/celery/worker/__init__.py", line 217, in start
[2011-11-11 20:22:50,808: WARNING/MainProcess] component.start()
[2011-11-11 20:22:50,808: WARNING/MainProcess] File "/Users/shashkin/python_v_env/lib/python2.7/site-packages/celery-2.1.4-py2.7.egg/celery/worker/listener.py", line 238, in start
[2011-11-11 20:22:50,808: WARNING/MainProcess] self.reset_connection()
[2011-11-11 20:22:50,808: WARNING/MainProcess] File "/Users/shashkin/python_v_env/lib/python2.7/site-packages/celery-2.1.4-py2.7.egg/celery/worker/listener.py", line 416, in reset_connection
[2011-11-11 20:22:50,808: WARNING/MainProcess] self.connection = self._open_connection()
[2011-11-11 20:22:50,808: WARNING/MainProcess] File "/Users/shashkin/python_v_env/lib/python2.7/site-packages/celery-2.1.4-py2.7.egg/celery/worker/listener.py", line 480, in _open_connection
[2011-11-11 20:22:50,809: WARNING/MainProcess] max_retries=conf.BROKER_CONNECTION_MAX_RETRIES)
[2011-11-11 20:22:50,809: WARNING/MainProcess] File "/Users/shashkin/python_v_env/lib/python2.7/site-packages/celery-2.1.4-py2.7.egg/celery/utils/__init__.py", line 276, in retry_over_time
[2011-11-11 20:22:50,809: WARNING/MainProcess] retval = fun(*args, **kwargs)
[2011-11-11 20:22:50,809: WARNING/MainProcess] File "/Users/shashkin/python_v_env/lib/python2.7/site-packages/celery-2.1.4-py2.7.egg/celery/worker/listener.py", line 472, in _establish_connection
[2011-11-11 20:22:50,809: WARNING/MainProcess] conn.connect() # evaluate connection
[2011-11-11 20:22:50,809: WARNING/MainProcess] File "/Users/shashkin/python_v_env/lib/python2.7/site-packages/carrot-0.10.7-py2.7.egg/carrot/connection.py", line 170, in connect
[2011-11-11 20:22:50,810: WARNING/MainProcess] return self.connection
[2011-11-11 20:22:50,810: WARNING/MainProcess] File "/Users/shashkin/python_v_env/lib/python2.7/site-packages/carrot-0.10.7-py2.7.egg/carrot/connection.py", line 135, in connection
[2011-11-11 20:22:50,810: WARNING/MainProcess] self._connection = self._establish_connection()
[2011-11-11 20:22:50,810: WARNING/MainProcess] File "/Users/shashkin/python_v_env/lib/python2.7/site-packages/carrot-0.10.7-py2.7.egg/carrot/connection.py", line 148, in _establish_connection
[2011-11-11 20:22:50,810: WARNING/MainProcess] return self.create_backend().establish_connection()
[2011-11-11 20:22:50,810: WARNING/MainProcess] File "/Users/shashkin/python_v_env/lib/python2.7/site-packages/carrot-0.10.7-py2.7.egg/carrot/connection.py", line 161, in create_backend
[2011-11-11 20:22:50,810: WARNING/MainProcess] return backend_cls(connection=self)
[2011-11-11 20:22:50,811: WARNING/MainProcess] TypeError
[2011-11-11 20:22:50,811: WARNING/MainProcess] :
[2011-11-11 20:22:50,811: WARNING/MainProcess] __init__() takes exactly 2 arguments (1 given)
[2011-11-11 20:22:50,811: INFO/MainProcess] process shutting down
我错过了什么?
2)稍后我想在我的应用程序中启动Celery。芹菜 - 挂架包安装后我该怎么办?我应该在应用的.ini
文件中添加芹菜的设置吗?有人可以给我任何一个例子,因为我在网上找到的那些对我没什么帮助。
感谢。
答案 0 :(得分:4)
这看起来像celery
包及其依赖项之间的版本兼容性问题。使用最新版本的芹菜,2.4.5你的例子就可以了。 2.1.4我得到了同样的错误。
如果由于任何原因您只需要2.1.4版本的芹菜,您必须找出降级所需的依赖项才能使其正常工作。通过查看回溯,很可能,它将是胡萝卜dependency
,但如果其他依赖项需要特定版本的carrot
,您可能会陷入依赖地狱。
我强烈建议使用带有pip的virtualenv,以便能够轻松地试验软件包的版本。尝试使用Linux存储库中的Python包开发一些东西会非常痛苦。
buildout versions或pip requirements解决了这类问题,但AFAIK没有针对芹菜的固定依赖版本。