Skip to content

Commit

Permalink
Merge pull request #34 from LCOGT/feature/reload_old_operations
Browse files Browse the repository at this point in the history
Reload an operation when it no longer exists in the cache
  • Loading branch information
jnation3406 authored Nov 5, 2024
2 parents 9dd1397 + 4512942 commit 8a0b732
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 8a0b732

Please sign in to comment.