I have two celery tasks, I want the second task to run only if the first is successful, something like this
@celery.task()
def add_together(a, b):
    return a + b
@celery.task()
def subtract(a, b):
    return a - b
First call
add_together.delay(2,2)
Second call
subtract.delay(4,2)
I want the second to run only if the first is successful
Instead of executing tasks in chain as proposed by @pAulseperformance because the second task will be executed though the first failed. You can use callbacks to execute a task only if the previous one succeed.
add_together.apply_async((2, 2), link=subtract.si(4,2))
For more about callbacks checkout this or this for task signature
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With