5

From what I have seen, the task state depends entirely on the value set for CELERY_TASK_RESULT_EXPIRES - if I check the task state within this interval after the task has finished executing, the state returned by:

AsyncResult(task_id).state

is correct. If not, the state will not be updated and will remain forever PENDING.

Can anyone explain me why does this happen? Is this a feature or a bug? Why is the task state depending on the result expiry time, even if I am ignoring results?

(Celery version: 3.0.23, result backend: AMQP)

Clara
  • 2,935
  • 6
  • 34
  • 49

1 Answers1

7

State and result is the same. The result backend was initially used to store return values then it was extended to store arbitrary states. The term result was not sufficient anymore as it implies that the task has completed. ignore_result should be ignore_state, but we haven't had the chance to rename that yet. I have a plan to clean up the terminology used here, but it will take some time to be backward compatible.

asksol
  • 19,129
  • 5
  • 61
  • 68
  • ignore_state sounds awkward btw, maybe someone can come up with a better name – asksol Oct 18 '13 at 17:33
  • Yeah, I assumed they are being returned in the same way...It's a bit misleading though that the result_expires setting influences the period that one can get the state, even though one ignores the result. I understand the reasoning behind though. Now my problem is that I am not really interested in the result, but I am interested in the state... – Clara Oct 18 '13 at 17:57
  • p.s. you could call it update_states or smth, instead of ignore_states – Clara Oct 19 '13 at 08:19
  • 1
    Right, result_expires should be state_expires and so on, in any case states must expire by default or it will just grow forever. Most applications will not need to keep states for a long time, but you can increase the expiry time if you please. If your tasks return big data then you can avoid returning it from the task (and thus keeping it out of the state), and instead write it somewhere else. – asksol Oct 19 '13 at 20:42
  • 1
    (continuing) E.g. if your task returns a big file you can move it somewhere and store a reference to it in the return value (an URL, or a database primary key, etc) – asksol Oct 19 '13 at 20:43