Django 如何获得所有芹菜任务?

Django 如何获得所有芹菜任务?,django,django-celery,Django,Django Celery,各位。我想在我的程序中获得所有芹菜任务。 就像Django管理员那样 但我找了很多没用的东西。 请。帮帮我 我认为你应该能够做这样的事情: from celery import current_app for name in sorted(current_app.tasks): if not name.startswith('celery.'): print(name) django芹菜检索管理员显示的任务列表。因此此代码将解决此问题: from celery im

各位。我想在我的程序中获得所有芹菜任务。 就像Django管理员那样

但我找了很多没用的东西。
请。帮帮我

我认为你应该能够做这样的事情:

from celery import current_app

for name in sorted(current_app.tasks):
    if not name.startswith('celery.'):
        print(name)

django芹菜
检索管理员显示的任务列表。

因此此代码将解决此问题:

from celery import current_app
def get_celery_all_tasks():
    current_app.loader.import_default_modules()
    tasks = list(sorted(name for name in current_app.tasks                         
             if not name.startswith('celery.')))
    return tasks

然后将返回芹菜旁边的所有芹菜任务。

谢谢。但是当我使用这个代码时,我并没有得到所有的任务。它只包含芹菜自己的任务。但事实上,我得到了很多成本任务,就像之前的图片一样。有什么主意吗?>>任务=列表(已排序(当前_app.tasks中的名称…如果不是name.startswith('celery'))>>>打印(任务)['NewCmdb.celery.debug_task']