如何在芹菜中重写__call__? [英] How to override __call__ in celery on main?

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

问题描述

我一直在使用抽象任务并覆盖 __调用__ 方法来处理一些事情,每个任务执行如下:

I've been using an abstract Task and overriding the __call__ method to handle some things before each task executed like such:

class CoreTaskHandler(Task):
    abstract = True
    def __call__(self, *args, **kwargs):

但是, __ call __ 方法在工作中执行,我需要一些覆盖这将在主要执行,而不是每次任务得到延迟的工作。

But the __call__ method gets executed on the worker, I need some override that will get executed on main, not the worker each time the task gets "delayed".

有谁有一个想法我会怎么做这样做? p>

Does anyone have an idea how would I go on about doing that?

推荐答案

我已经通过覆盖任务中的apply_sync方法来修复这个问题:

I have fixed this by overriding the apply_sync method in Task:

class CoreTaskHandler(Task):
    abstract = True
    def apply_async(self, *args, **kwargs):

        ........

        return super(CoreTaskHandler, self).apply_async(*args, **kwargs)

这篇关于如何在芹菜中重写__call__?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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