Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override __call__ in celery on main?

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?

like image 434
Bojan Jovanovic Avatar asked Dec 31 '25 20:12

Bojan Jovanovic


1 Answers

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)
like image 157
Bojan Jovanovic Avatar answered Jan 03 '26 09:01

Bojan Jovanovic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!