How to override __call__ in celery on main?

倖福魔咒の 提交于 2019-12-11 02:48:38

问题


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):

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

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


回答1:


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)


来源:https://stackoverflow.com/questions/21574395/how-to-override-call-in-celery-on-main

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!