Skip to content

Commit

Permalink
Reload an operation when it no longer exists in the cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon committed Sep 13, 2024
1 parent e5e3aa2 commit 4512942
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions datalab/datalab_session/viewsets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from rest_framework import viewsets
from rest_framework.response import Response
from django_filters.rest_framework import DjangoFilterBackend

from datalab.datalab_session.serializers import DataSessionSerializer, DataOperationSerializer
Expand All @@ -18,6 +19,15 @@ def perform_create(self, serializer):
serializer.save(session_id=self.kwargs['session_pk'], cache_key=operation.cache_key)
operation.perform_operation()

def retrieve(self, request, *args, **kwargs):
instance = self.get_object()
serializer = self.get_serializer(instance)
if instance.status == 'PENDING' and not instance.output:
operation = available_operations().get(instance.name)(instance.input_data)
operation.perform_operation()

return Response(serializer.data)


class DataSessionViewSet(viewsets.ModelViewSet):
serializer_class = DataSessionSerializer
Expand Down

0 comments on commit 4512942

Please sign in to comment.