Skip to content

Commit 8d754d5

Browse files
committed
[scheduler:api] Add last_jobs field to tasks data endpoint
The field 'last_jobs' is included when the data about a task is requested. This field lists the last 10 jobs run by the task. Signed-off-by: Santiago Dueñas <sduenas@bitergia.com>
1 parent fcc35eb commit 8d754d5

File tree

1 file changed

+20
-4
lines changed
  • src/grimoirelab/core/scheduler

1 file changed

+20
-4
lines changed

src/grimoirelab/core/scheduler/api.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,20 @@ def get_paginated_response(self, data):
5252

5353
class EventizerTaskListSerializer(serializers.ModelSerializer):
5454
status = serializers.CharField(source='get_status_display')
55+
last_jobs = serializers.SerializerMethodField()
5556

5657
class Meta:
5758
model = EventizerTask
5859
fields = [
59-
'uuid', 'status', 'runs', 'failures', 'last_run',
60-
'scheduled_at', 'datasource_type', 'datasource_category',
60+
'uuid', 'status', 'runs', 'failures', 'last_run', 'last_jobs',
61+
'scheduled_at', 'datasource_type', 'datasource_category'
6162
]
6263

64+
def get_last_jobs(self, obj):
65+
job_klass = get_registered_task_model('eventizer')[1]
66+
jobs = job_klass.objects.filter(task=obj).order_by('-job_num')[:10]
67+
return EventizerJobSummarySerializer(jobs, many=True).data
68+
6369

6470
class EventizerJobListSerializer(serializers.ModelSerializer):
6571
status = serializers.CharField(source='get_status_display')
@@ -80,7 +86,17 @@ class Meta:
8086
fields = [
8187
'uuid', 'status', 'runs', 'failures', 'last_run',
8288
'job_interval', 'scheduled_at',
83-
'datasource_type', 'datasource_category'
89+
'datasource_type', 'datasource_category',
90+
]
91+
92+
93+
class EventizerJobSummarySerializer(serializers.ModelSerializer):
94+
status = serializers.CharField(source='get_status_display')
95+
96+
class Meta:
97+
model = get_registered_task_model('eventizer')[1]
98+
fields = [
99+
'uuid', 'job_num', 'status', 'scheduled_at', 'finished_at'
84100
]
85101

86102

@@ -121,7 +137,7 @@ def get_logs(self, obj):
121137

122138

123139
class EventizerTaskList(generics.ListAPIView):
124-
queryset = EventizerTask.objects.all()
140+
queryset = EventizerTask.objects.all().order_by('-scheduled_at')
125141
serializer_class = EventizerTaskListSerializer
126142
pagination_class = EventizerPaginator
127143

0 commit comments

Comments
 (0)