Skip to content

Instantly share code, notes, and snippets.

@aballah-chamakh
Last active November 17, 2019 05:43
Show Gist options
  • Select an option

  • Save aballah-chamakh/9bcabaa2b966cf781b869d04944317aa to your computer and use it in GitHub Desktop.

Select an option

Save aballah-chamakh/9bcabaa2b966cf781b869d04944317aa to your computer and use it in GitHub Desktop.
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