在cherrypy中启动celery任务

发布于 2025-01-05 05:44:03 字数 862 浏览 4 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自由如风 2025-01-12 05:44:03

如果您在调试模式下运行 celeryd (celeryd -l debug),您应该会得到一个提示:(

[2012-02-15 09:34:35,484: ERROR/MainProcess] Received unregistered task of type 'default.create_agent'.
The message has been ignored and discarded.

Did you remember to import the module containing this task?
Or maybe you are using relative imports?
Please see http://bit.ly/gLye1c for more information.

为了将来参考,当您遇到类似问题时,请在 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:

[2012-02-15 09:34:35,484: ERROR/MainProcess] Received unregistered task of type 'default.create_agent'.
The message has been ignored and discarded.

Did you remember to import the module containing this task?
Or maybe you are using relative imports?
Please see http://bit.ly/gLye1c for more information.

(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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文