title: How to make a celery task fail from within the task?
body: <p>Under some conditions, I want to make a celery task fail from within that task. I tried the following:</p>
  
  <pre><code>from celery.task import task
  from celery import states
  
  @task()
  def run_simulation():
      if some_condition:
          run_simulation.update_state(state=states.FAILURE)
          return False
  </code></pre>
  
  <p>However, the task still reports to have succeeded:</p>
  
  <blockquote>
    <p>Task sim.tasks.run_simulation[9235e3a7-c6d2-4219-bbc7-acf65c816e65]
    succeeded in 1.17847704887s: False</p>
  </blockquote>
  
  <p>It seems that the state can only be modified while the task is running and once it is completed - celery changes the state to whatever it deems is the outcome (refer to <a href="http://community.webfaction.com/questions/2841/django-celery-task-custom-states" rel="noreferrer">this question</a>). Is there any way, without failing the task by raising an exception, to make celery return that the task has failed?</p>