2

How am I supposed to retrieve a task's name when I've got its AsyncResult object and consequently its id?

For example if I launch two of my tasks in a chain:

>>> task_chain = (task_A.s() | task_B.s())
>>> async_result = task_chain.apply_async()

I can retrieve the id of task_B and consequently task_A using the internal _parents() method like this:

>>> async_result.id
>>> 2ed28e84-0673-4491-a56f-c5ab8dfb5725
>>> async_result._parents()[0].id
>>> e793f4dc-5110-4f57-8f98-8caa48c40528

However when I attempt to retrieve the task_name I get nothing back:

>>> async_result.task_name
>>> async_result._parents()[0].task_name

Why is this happening? Could this possibly be a bug? I have noticed that by submitting a single task, the task_name attribute of AsyncResult works perfectly fine and returns the proper task name.

Is there any other way to retrieve a task's name from the AsyncResult object?

Thank you all in advance.

P.S. I have already found a similar question here but no one seems to propose a pratical and working solution.

celery-users

UPDATE

Apparently it seems that I've a hit a wall with this one. There is an open ticket on github about the exact same issue with the difference that it concerns groups instead of chains.

https://github.com/celery/celery/issues/2504

stratis
  • 7,750
  • 13
  • 53
  • 94

1 Answers1

-3

One way to do it save it into the cache like that:

cache.set(hash_key, result, 30)  # save result to cache for 30 seconds

and you can retrieve it by its key:

result = cache.get(hash_key) 

Assuming its not InMemory cache

UPDATE

Sorry I've misinterpreted the question.

What I think happened is that the result of the task_chain AsyncResult gets initialized with only the task id as its the only requirement. Maybe if you try that:

async_result = task_chain.apply_async(name="mytasks")

but I would't count on it

Fanis Despoudis
  • 362
  • 1
  • 7
  • Your first answer is irrelevant. Your update on the other hand suggests using the `name` parameter of the `apply_async` method which takes no such attribute. – stratis May 10 '15 at 19:08