问题
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