Celery - Get task id for current task

后端 未结 3 931
小蘑菇
小蘑菇 2020-12-08 03:36

How can I get the task_id value for a task from within the task? Here\'s my code:

from celery.decorators import task
from django.core.cache import cache

@ta         


        
3条回答
  •  北海茫月
    2020-12-08 04:05

    Celery does set some default keyword arguments if the task accepts them. (you can accept them by either using **kwargs, or list them specifically)

    @task
    def do_job(path, task_id=None):
        cache.set(task_id, operation_results)
    

    The list of default keyword arguments is documented here: http://ask.github.com/celery/userguide/tasks.html#default-keyword-arguments

提交回复
热议问题