Alexander Sysoev
Alexander Sysoev

Reputation: 835

Celery task handlers vs signals

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

Upvotes: 2

Views: 3302

Answers (1)

twil
twil

Reputation: 6162

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.

Upvotes: 2

Related Questions