芹菜打败方法任务不起作用

编程入门 行业动态 更新时间:2024-10-14 06:22:02
本文介绍了芹菜打败方法任务不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试在方法任务上运行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?

更多推荐

芹菜打败方法任务不起作用

本文发布于:2023-11-24 13:19:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1625361.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:芹菜   不起作用   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!