Python Celery: Updating the state of an AsyncResult

1.6k views Asked by At

After a parent task succeeds, depending on some of his child tasks results, I wish to update the task state.

However: 1/ I cannot find a way to retrieve the actual task instance based on its id, only its AsyncResult

def level5_success(task_id):
  result = app.AsyncResult(task_id)
  # Set the parent task state (do not work)
  app.AsyncResult(task_id).update_state(state='HOWAREYOUDOING') 

2/ I cannot find a way to update the state of an AsyncResult, only with the task itself using update_state:

def on_level4_success(sender, *args, **kwargs):
  sender.update_state(state='HOWAREYOUDOING')

Any idea?

1

There are 1 answers

2
bwarren2 On

It feels like you are operating outside the bounds of what celery is designed to do. Coordination of work state and process is supposed to be done with the worker canvas, not by monkeying around with the celery internals. Even if you manage to get it to work, I doubt that state hacking is in the contract celery intends to keep with its API; it is entirely possible that your work will be broken by future changes to celery.

What are you trying to do that you cannot do with groups, chords and chains?