芹菜python对象方法 [英] celery python object methods

查看:37
本文介绍了芹菜python对象方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试围绕python对象方法获取celery任务包装器.喜欢:

I am trying to get celery tasks wrapper around a python object method. Like:

 class A:
      @task
      def test_task(self,args):
        print "BLah..test"

   def main():
     a= A()
     args = {}
     a.test_task(args)

现在,此操作失败,并显示错误test_task接受至少2个参数(给定1个).我的理解是自我对象没有通过.为什么会这样呢?以及我该如何解决?

Now this fails with error test_task takes atleast 2 arguments (1 given). My understanding is the self object is not getting passed. Why is this so? and how do i work around this?

更新:真的是我对芹菜缺乏了解.@task装饰器仅用于添加/处理与celery任务相关的参数.它不会自动使对函数的每次调用都成为一项芹菜任务.该函数必须称为a.test_task.delay(args)..其中存在问题...

Update: It really was my lack of understanding of celery. the @task decorator is just to add/handle the celery task related parameters. it doesn't automatically make every call to the function a celery task. the function must be called as a.test_task.delay(args).. therein the problem...

推荐答案

您是否需要将 test_task 作为方法?简单功能可以工作吗?还是可以使用静态方法?顺便说一句,您的 main 函数不使用celery执行 test_task ,而是以简单的方法运行它.

Do you need to have test_task as method? Will simple function work? Or could you use static method? BTW, your main function doesn't use celery to execute test_task, it runs it as simple method.

这篇关于芹菜python对象方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆