How to make a celery task fail from within the task?

To mark a task as failed without raising an exception, update the task state to FAILURE and then raise an Ignore exception, because returning any value will record the task as successful, an example: from celery import Celery, states from celery.exceptions import Ignore app = Celery(‘tasks’, broker=”amqp://guest@localhost//”) @app.task(bind=True) def run_simulation(self): if some_condition: # manually update … Read more