我正在尝试在方法任务上运行celerybeat,但无法正常工作。这是一个示例设置:
I'm trying to run celerybeat on a method task, and can't get anything to work out properly. Here's an example setup:
from celery.contrib.methods import task_method from celery import Celery, current_app celery=celery('tasks', broker='amqp://guest@localhost//') celery.config_from_object("celeryconfig") class X(object): @celery.task(filter=task_method, name="X.ppp") def ppp(self): print "ppp",而我的celeryconfig.py文件是
and my celeryconfig.py file is
from datetime import timedelta CELERYBEAT_SCHEDULE = { 'test' : { 'task' : 'X.ppp', 'schedule' : timedelta(seconds=5) }, }当我跑步芹菜节,出现类似以下错误:
When I run celery beat, I'm getting errors like:
task X.ppp raised exception, TypeError('ppp() takes exactly 1 argument, (0 given)当我将方法转换为普通函数并用`@cel ery.task,它确实可以正常工作,因此其余的设置似乎都可以正常工作。我在有关方法任务的文档中看到了的警告,但无法真正找出问题所在。有谁知道如何解决这个问题?
When I turn the method into a normal function and decorate it with `@celery.task', it does work, so the rest of the setup seems to be working. I see the caveats in the docs about method tasks, but can't really sort out where the problem is. Does anyone know how to resolve this?
推荐答案问题是Celerybeat在调用该方法之前不会实例化X。如果该方法未绑定到对象,则task_method过滤器默认会调用unbound方法。
The problem is that Celerybeat will not instantiate X before calling the method. The task_method filter defaults to calling the unbound method if the method is not bound to an object.
我的问题是,您要在这里完成什么? X没有状态,那么为什么不使用module-evel函数呢?
My question is, what are you trying to accomplish here? X has no state, so why not use a module-evel function?
更多推荐
芹菜打败方法任务不起作用
发布评论