Skip to content

Commit

Permalink
add deprecated in stats api
Browse files Browse the repository at this point in the history
  • Loading branch information
raylrui committed Dec 10, 2024
1 parent 2b205c7 commit be82d91
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class WorkflowRunCountByStatusSerializer(serializers.Serializer):
failed = serializers.IntegerField()
resolved = serializers.IntegerField()
ongoing = serializers.IntegerField()
deprecated = serializers.IntegerField()

def update(self, instance, validated_data):
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class StateViewSet(mixins.CreateModelMixin, mixins.UpdateModelMixin, mixins.List
"""
valid_states_map = {
'RESOLVED': ['FAILED'],
'DEPRECATED': ['SUCCEED']
'DEPRECATED': ['SUCCEEDED']
}

def get_queryset(self):
Expand Down Expand Up @@ -58,7 +58,8 @@ def create(self, request, *args, **kwargs):
data = request.data.copy()
data['timestamp'] = timezone.now()
data['workflow_run'] = wfr_orcabus_id

data['status'] = request_status

serializer = self.get_serializer(data=data)
serializer.is_valid(raise_exception=True)
serializer.save()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def exclude_params(params):
~Q(states__status="FAILED") &
~Q(states__status="ABORTED") &
~Q(states__status="SUCCEEDED") &
~Q(states__status="RESOLVED")
~Q(states__status="RESOLVED") &
~Q(states__status="DEPRECATED")
)

if status:
Expand Down Expand Up @@ -131,6 +132,11 @@ def count_by_status(self, request):
states__status="RESOLVED"
).count()

deprecated_count = annotate_queryset.filter(
states__timestamp=F('latest_state_time'),
states__status="DEPRECATED"
).count()

ongoing_count = base_queryset.filter(
~Q(states__status="FAILED") &
~Q(states__status="ABORTED") &
Expand All @@ -143,6 +149,7 @@ def count_by_status(self, request):
'aborted': aborted_count,
'failed': failed_count,
'resolved': resolved_count,
'deprecated': deprecated_count,
'ongoing': ongoing_count
}, status=200)

Expand Down

0 comments on commit be82d91

Please sign in to comment.