How to use 'throws' parameter in celery using signature?

49 views Asked by At

I am using Django with celery. I want to ignore an exception for a task when queuing it inside a group, but not when queuing it directly. For this reason the decorator option throws isn't useful because it will always ignore the exception, like in the following example:

#tasks.py
from celery import group, shared_task

@shared_task(throws=(TimeoutError,))
def raise_exception(n):
    print("I'm going to fail")

    raise TimeoutError(n)

@shared_task
def foo_task():
    task_group = group(
        raise_exception.s(i)
        for i in range(3)
    )
    task_group()

I am trying the following code but it doesn't work:

#tasks.py
from celery import group, shared_task

@shared_task
def raise_exception(n):
    print("I'm going to fail")
    raise TimeoutError(n)

@shared_task
def foo_task():
    raise_exception.throws=(TmeoutError,)
    task_group = group(
        raise_exception.s(i)
        for i in range(3)
    )
    task_group()

How can I set the value of throws after the task definition? Like when building a group of tasks.

0

There are 0 answers