Skip to content

Commit

Permalink
add api for rerun/deprecated vlidation
Browse files Browse the repository at this point in the history
  • Loading branch information
raylrui committed Dec 11, 2024
1 parent be82d91 commit 4bf33f1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_current_state(self, obj) -> dict:
class WorkflowRunListParamSerializer(OptionalFieldsMixin, WorkflowRunBaseSerializer):
class Meta:
model = WorkflowRun
fields = "__all__"
fields = ["orcabus_id", "workflow", "analysis_run", "workflow_run_name", "portal_run_id", "execution_id", "comment",]

class WorkflowRunSerializer(WorkflowRunBaseSerializer):
from .workflow import WorkflowMinSerializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

class AllowedRerunWorkflow(StrEnum):
RNASUM = "rnasum"


class AllowedRerunWorkflowSerializer(serializers.Serializer):
is_valid = serializers.BooleanField()
valid_workflows = serializers.ListField(child=serializers.CharField())

class BaseRerunInputSerializer(serializers.Serializer):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

router = OptionalSlashDefaultRouter()

router.register("workflowrun/stats", WorkflowRunStatsViewSet, basename="workflowrun_list_all") # put it before workflowrun, as it will match the workflowrun/list_all/ url
router.register(r"workflowrun/stats", WorkflowRunStatsViewSet, basename="workflowrun_list_all") # put it before workflowrun, as it will match the workflowrun/list_all/ url
router.register(r"analysis", AnalysisViewSet, basename="analysis")
router.register(r"analysisrun", AnalysisRunViewSet, basename="analysisrun")
router.register(r"analysiscontext", AnalysisContextViewSet, basename="analysiscontext")
Expand All @@ -29,7 +29,6 @@
router.register(r"workflowrun", WorkflowRunActionViewSet, basename="workflowrun-action")
router.register(r"payload", PayloadViewSet, basename="payload")

# may no longer need this as it's currently included in the detail response for an individual WorkflowRun record
router.register(
"workflowrun/(?P<orcabus_id>[^/.]+)/state",
StateViewSet,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import extend_schema, PolymorphicProxySerializer
from rest_framework.decorators import action
from rest_framework import mixins, status
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet
Expand Down Expand Up @@ -29,6 +31,11 @@ class StateViewSet(mixins.CreateModelMixin, mixins.UpdateModelMixin, mixins.List
def get_queryset(self):
return State.objects.filter(workflow_run=self.kwargs["orcabus_id"])

@extend_schema(responses=OpenApiTypes.OBJECT, description="Valid states map for new state creation, update")
@action(detail=False, methods=['get'], url_name='valid_states_map', url_path='valid_states_map')
def get_valid_states_map(self, request, **kwargs):
return Response(self.valid_states_map)

def create(self, request, *args, **kwargs):
"""
Create a customed new state for a workflow run.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from workflow_manager.models.utils import create_portal_run_id
from workflow_manager.serializers.library import LibrarySerializer
from workflow_manager.serializers.payload import PayloadSerializer
from workflow_manager.serializers.workflow_run_action import AllowedRerunWorkflow, RERUN_INPUT_SERIALIZERS
from workflow_manager.serializers.workflow_run_action import AllowedRerunWorkflow, RERUN_INPUT_SERIALIZERS, AllowedRerunWorkflowSerializer
from workflow_manager.models import (
WorkflowRun,
State,
Expand All @@ -27,6 +27,17 @@ class WorkflowRunActionViewSet(ViewSet):
queryset = WorkflowRun.objects.prefetch_related('states').all()
orcabus_id_prefix = WorkflowRun.orcabus_id_prefix

@extend_schema(responses=AllowedRerunWorkflowSerializer, description="Allowed rerun workflows")
@action(detail=True, methods=['get'], url_name='validate_rerun_workflows', url_path='validate_rerun_workflows')
def validate_rerun_workflows(self, request, *args, **kwargs):
wfl_run = get_object_or_404(self.queryset, pk=kwargs.get('pk'))
is_valid = wfl_run.workflow.workflow_name in AllowedRerunWorkflow
reponse = {
'is_valid': is_valid,
'valid_workflows': AllowedRerunWorkflow
}
return Response(reponse, status=status.HTTP_200_OK)

@extend_schema(
request=PolymorphicProxySerializer(
component_name='WorkflowRunRerun',
Expand Down Expand Up @@ -63,7 +74,7 @@ def rerun(self, request, *args, **kwargs):
status=status.HTTP_400_BAD_REQUEST)

detail = construct_rerun_eb_detail(wfl_run, serializer.data)
emit_wrsc_api_event(detail)
# emit_wrsc_api_event(detail)

return Response(detail, status=status.HTTP_200_OK)

Expand Down

0 comments on commit 4bf33f1

Please sign in to comment.