I am using celery 5.1.2 in my project, In the celery task I want to get celery task id, Now I am doing like this:
@app.task(ignore_result=True, name='pydolphin.dolphin.tasks.tasks')
def pull_channel_impl(channel_id, level):
print(app.current_task.task_id)
rss = RssSource()
source = rss.select_channel_by_id(channel_id)
RssPullImpl.single_rss_hub(source, rss, level)
but when I run this code, show this error:
[2021-07-19 23:55:38,394: INFO/MainProcess] Task pydolphin.dolphin.tasks.tasks[5eaff308-aa3d-4963-a40e-4aee30b7f509] received
[2021-07-19 23:55:38,410: ERROR/ForkPoolWorker-1] Task pydolphin.dolphin.tasks.tasks[2382fc1f-4eb0-4377-b1be-502cce2b6156] raised unexpected: AttributeError("'pull_channel_impl' object has no attribute 'task_id'",)
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/celery/app/trace.py", line 450, in trace_task
R = retval = fun(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/celery/app/trace.py", line 731, in __protected_call__
return self.run(*args, **kwargs)
File "/opt/apps/pydolphin/dolphin/tasks/tasks.py", line 27, in pull_channel_impl
print(app.current_task.task_id)
AttributeError: 'pull_channel_impl' object has no attribute 'task_id'
[2021-07-19 23:55:38,431: ERROR/ForkPoolWorker-1] Task pydolphin.dolphin.tasks.tasks[15b1d5f5-5ab4-4c21-ac9e-9ed86d4ac628] raised unexpected: AttributeError("'pull_channel_impl' object has no attribute 'task_id'",)
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/celery/app/trace.py", line 450, in trace_task
R = retval = fun(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/celery/app/trace.py", line 731, in __protected_call__
return self.run(*args, **kwargs)
File "/opt/apps/pydolphin/dolphin/tasks/tasks.py", line 27, in pull_channel_impl
print(app.current_task.task_id)
AttributeError: 'pull_channel_impl' object has no attribute 'task_id'
[2021-07-19 23:55:38,452: ERROR/ForkPoolWorker-1] Task pydolphin.dolphin.tasks.tasks[5eaff308-aa3d-4963-a40e-4aee30b7f509] raised unexpected: AttributeError("'pull_channel_impl' object has no attribute 'task_id'",)
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/celery/app/trace.py", line 450, in trace_task
R = retval = fun(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/celery/app/trace.py", line 731, in __protected_call__
return self.run(*args, **kwargs)
File "/opt/apps/pydolphin/dolphin/tasks/tasks.py", line 27, in pull_channel_impl
print(app.current_task.task_id)
AttributeError: 'pull_channel_impl' object has no attribute 'task_id'
am I doing wrong? in my project shows the task id was exists in the attribute, what should I do to fix this problem?