Last active
November 17, 2019 05:43
-
-
Save aballah-chamakh/9bcabaa2b966cf781b869d04944317aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from rest_framework.decorators import action | |
| from rest_framework.response import Response | |
| from rest_framework import viewsets,status,generics | |
| from .serializers import InferenceSerializer | |
| from .models import Inference | |
| from celery.result import AsyncResult | |
| class InferenceViewSet(viewsets.ModelViewSet): | |
| serializer_class = InferenceSerializer | |
| queryset = Inference.objects.all() | |
| @action(methods=['GET'],detail=True) | |
| def monitor_inference_progress(self,request,slug): | |
| inference_obj = self.get_object() | |
| progress = 100 | |
| result = AsyncResult(inference_obj.task_id) | |
| if isinstance(result.info, dict): | |
| progress = result.info['progress'] | |
| description = result.state | |
| return Response({'progress':progress,'description':description},status=status.HTTP_200_OK) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment