在cherrypy中启动celery任务
我正在使用cherrypy构建宁静的界面,我需要启动一些芹菜任务 但它似乎不起作用,我不知道为什么?
也许有人面临过这样的情况。
所以,我有celeryconfig.py
CELERY_RESULT_BACKEND = "database"
CELERY_RESULT_DBURI = "sqlite:///celerydb.sqlite"
CELERY_IMPORTS = ("tasks", )
CELERY_RESULT_ENGINE_OPTIONS = {"echo": True}
BROKER_TRANSPORT = "sqlalchemy"
BROKER_HOST = "sqlite:///celerydb.sqlite"
和tasks.py
from celery.task import task
@task
def create_agent(agent_id):
print ("do something")
我正在启动celeryd
celeryd -l INFO
我还有一个请求处理程序(CherryPy)
class Resource(object):
def POST(self):
create_agent.delay(1)
我可以从python控制台调用create_agent.delay(1)任务,celery工作人员获取任务并工作 但是当在cherrypy中调用create_agent.delay(1)时(通过触摸适当的url) 芹菜工人根本没有得到任务。
还有更多。我用的是python3.2
i am building restful interface using cherrypy and i need to launch some celery tasks
But it seems doesn't work and i have no idea why?
Myaybe someone was faced with such.
So, i have celeryconfig.py
CELERY_RESULT_BACKEND = "database"
CELERY_RESULT_DBURI = "sqlite:///celerydb.sqlite"
CELERY_IMPORTS = ("tasks", )
CELERY_RESULT_ENGINE_OPTIONS = {"echo": True}
BROKER_TRANSPORT = "sqlalchemy"
BROKER_HOST = "sqlite:///celerydb.sqlite"
And tasks.py
from celery.task import task
@task
def create_agent(agent_id):
print ("do something")
I am launching celeryd
celeryd -l INFO
Also i have a request handler (CherryPy)
class Resource(object):
def POST(self):
create_agent.delay(1)
I can call create_agent.delay(1) task from the python console and celery worker gets the task and work
But when create_agent.delay(1) is called in cherrypy (by touching appropriate url)
celery worker does not get the task at all.
And more. I use python3.2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在调试模式下运行 celeryd (
celeryd -l debug
),您应该会得到一个提示:(为了将来参考,当您遇到类似问题时,请在
debug
模式下运行 celeryd ;info
不会告诉您太多信息。)该 bit.ly 网址指向此:
http://ask.github.com/celery /userguide/tasks.html#automatic-naming-and-relative-imports
您应该能够通过将装饰器更改为以下内容来解决此错误:
@task(name='tasks.create_agent')
我正在运行 python 2.7 和 celery 2.3.1。我能够重现您的问题,并且上述修复对我有用。
我希望这有帮助。
If you run celeryd in debug mode (
celeryd -l debug
), you should get a hint:(For future reference, run celeryd in
debug
mode when you have issues like this;info
isn't going to tell you much.)That bit.ly url points to this:
http://ask.github.com/celery/userguide/tasks.html#automatic-naming-and-relative-imports
You should be able to resolve this error by changing your decorator to this:
@task(name='tasks.create_agent')
I'm running python 2.7 and celery 2.3.1. I was able to reproduce your issue and the fix above worked for me.
I hope that helps.