fix: celeryinfo取值错误

This commit is contained in:
caoqianming 2024-03-15 16:41:13 +08:00
parent c0567f5a55
commit 077707f493
1 changed files with 7 additions and 2 deletions

View File

@ -108,18 +108,23 @@ class CeleryMonitor:
def get_info(cls):
count_active_task = 0
count_scheduled_task = 0
count_registered_task = 0
active_tasks = celery_inspect.active()
if active_tasks:
_, first_value = active_tasks.popitem()
count_active_task = len(first_value)
scheduled_tasks = celery_inspect.scheduled()
if scheduled_tasks:
_, first_value = active_tasks.popitem()
_, first_value = scheduled_tasks.popitem()
count_scheduled_task = len(first_value)
print(active_tasks)
registered_tasks = celery_inspect.registered()
if registered_tasks:
_, first_value = registered_tasks.popitem()
count_registered_task = len(first_value)
return {
'count_active_task': count_active_task,
'count_scheduled_task': count_scheduled_task,
'count_registered_task': count_registered_task,
}