If I have the original task I can get the arguments from task.request.args
, but if I only have the task ID is there a way to get the arguments? It doesn't look like there is a way to get them from an AsyncResult
object, and as far as I can tell there isn't a way to re-create the task.
I want to do this because I have a frontend that polls the backend for updates on tasks, and it would be useful if it could display the task arguments. Seeing as the arguments are stored with the broker, this should be possible, at least when the task is in pending state.
Naturally there are other ways to do this, but it would be a clean way to do things.
If the task is in pending state or if it is executing currently, you can see the arguments of the task. The easiest way is to use celery inspect method.
from celery.task.control import inspect
i = inspect()
active_tasks = i.active()
reserved_tasks = i.reserved()
scheduled_tasks = i.scheduled()
You can iterate over them and by using task id, you can get all the task details like this
{'acknowledged': True,
'args': '(1000,)',
'delivery_info': {'exchange': '',
'priority': 0,
'redelivered': None,
'routing_key': 'celery'},
'hostname': 'celery@pavilion',
'id': '30d41ba2-3e71-49ce-8e7d-830ba1152256',
'kwargs': '{}',
'name': 't.wait',
'time_start': 1007.945882783,
'type': 't.wait',
'worker_pid': 10560}
Alterantively, you can also read data from broker, deseriaze it and you can get the task agruments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With