Ravinder Baid
Ravinder Baid

Reputation: 395

Celery- Disabling signals

I have used celery signals it is working fine

@shared_task(name="execute_task")
def execute(*args,**kwargs):
   return 2+2

@task_success.connect
def task_success_handler(sender=None, headers=None, body=None, **kwargs):
   print(pass)

After the execute task is executed the task success signal is called, but I want to disable this call. Is it achievable?

Upvotes: 1

Views: 486

Answers (1)

Dristy Srivastava
Dristy Srivastava

Reputation: 146

Yes we can do this, celery signals also come with disconnect feature, so what you need to do is

from celery import signals
@shared_task(name="execute_task")
def execute(*args,**kwargs):
   signals.task_success.disconnect(task_success_handler)
   return 2+2

This way the success function won't be called.

Upvotes: 4

Related Questions