Search code examples
pythoncelerycelery-task

Celery task handlers vs signals


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


Solution

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