Celery task handlers vs signals

3.1k Views Asked by At

Celery tasks have on_success handler and task-success signal. what is the difference?

1

There are 1 best solutions below

0
On BEST ANSWER

As stated in the docs:

Abstract classes are not registered, but are used as the base class for new task types.

So apparently handlers are methods that you can override to do something. You can see example of custom handler after_return in the docs actually:

from celery import Task

class DebugTask(Task):
    abstract = True

    def after_return(self, *args, **kwargs):
        print('Task returned: {0!r}'.format(self.request)

Signals are means of decoupling, so you can make your code listening from outside for some event to happen and act appropriately.