When I try to access the taskname from a result that has come from group, None is returned
Python(s): 3.3.6, 3.4.2
celery: 3.1.17
proj/celery.py
from celery import Celery
app = Celery('proj',
broker='amqp://',
backend='amqp://',
include=['proj.tasks'])
# Optional configuration, see the application user guide.
app.conf.update(
CELERY_TASK_RESULT_EXPIRES=3600,
)
if __name__ == '__main__':
app.start()
proj/tasks.py
from proj.celery import app
@app.task
def add(x, y):
return x + y
@app.task
def mul(x, y):
return x * y
run_add.py
from celery import group
from proj import tasks
import logging
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
results = group([
tasks.mul.s(4,4),
tasks.add.s(3,3)
]).delay()
while results.waiting():
pass
if results.successful():
for result in results:
log.info('ID: {}, name: {}'.format(result.task_id, result.task_name))
Result:
INFO:__main__:ID: c2fa4f30-0691-41ee-8f7b-e7dcbf32d09a, name: None
INFO:__main__:ID: f545bfa0-2ad7-40b3-9d05-561d4c1eba7e, name: None
Same thing seems to also be happening with chains too.
There's also a stackoverflow post about it:
Get the task_name from AsyncResult when submitting chains in celery
task_name is a local field, it's not used for anything anymore and I guess it should be removed completely.
The result sent does not actually have a name field, it was used at some point to serialize the backend with the result when using pickle, but that is accomplished differently now.
@ask is there no way to grab the task_name now? We have an endpoint used to expose task data to the web, and we'd like to, given an AsyncResult, log the name of the task.
Most helpful comment
@ask is there no way to grab the task_name now? We have an endpoint used to expose task data to the web, and we'd like to, given an AsyncResult, log the name of the task.