Skip to content

Commit

Permalink
celery 查看异步任务详情
Browse files Browse the repository at this point in the history
  • Loading branch information
woshiyanghai committed Sep 18, 2024
1 parent 2f0d0f4 commit 4bace95
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions sql/utils/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from celery import signature
from celery.result import AsyncResult
from celery.exceptions import SoftTimeLimitExceeded
from django.http import JsonResponse
import logging
import pytz

Expand Down Expand Up @@ -56,11 +57,12 @@ def del_schedule(name):
except Exception as e:
print(f"终止任务时发生错误:{str(e)}")


def task_info(name):
"""获取定时任务详情"""
try:
periodic_task = PeriodicTask.objects.get(name=name)
return periodic_task
except PeriodicTask.DoesNotExist:
return None
task_result = AsyncResult(name)
response = {
'task_id': name,
'status': task_result.state,
'result': task_result.result
}
return JsonResponse(response)

0 comments on commit 4bace95

Please sign in to comment.