mirror of https://github.com/doccano/doccano.git
pythonannotation-tooldatasetsactive-learningtext-annotationdatasetnatural-language-processingdata-labelingmachine-learning
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
623 B
19 lines
623 B
from celery.result import AsyncResult
|
|
from rest_framework.permissions import IsAuthenticated
|
|
from rest_framework.response import Response
|
|
from rest_framework.views import APIView
|
|
|
|
|
|
class TaskStatus(APIView):
|
|
permission_classes = (IsAuthenticated,)
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
task = AsyncResult(kwargs['task_id'])
|
|
ready = task.ready()
|
|
error = ready and not task.successful()
|
|
|
|
return Response({
|
|
'ready': ready,
|
|
'result': task.result if ready and not error else None,
|
|
'error': {'text': str(task.result)} if error else None,
|
|
})
|