Skip to content

Commit 5f28413

Browse files
authored
feat: show number of failed celery tasks on stats page (#2820)
1 parent 5777ccb commit 5f28413

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

dataworkspace/dataworkspace/apps/dw_admin/views.py

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from datetime import datetime, timedelta
44

55
from botocore.exceptions import ClientError
6+
from celery import states
67
from dateutil.rrule import DAILY, rrule
78

89
from django import forms
@@ -19,6 +20,7 @@
1920
from django.urls import reverse
2021
from django.utils.timesince import timesince
2122
from django.views.generic import FormView, CreateView, TemplateView
23+
from django_celery_results.models import TaskResult
2224

2325
from dataworkspace.apps.applications.models import ApplicationInstance
2426
from dataworkspace.apps.core.boto3_client import get_s3_client
@@ -524,4 +526,9 @@ def get_context_data(self, **kwargs):
524526
perm_query_chart_data[day.date()] = 0
525527
ctx["perm_query_chart_data"] = sorted(perm_query_chart_data.items())
526528

529+
# Number of failed celery tasks in the last 24 hours
530+
ctx["failed_celery_tasks_24_hours"] = TaskResult.objects.filter(
531+
date_done__gte=datetime.now() - timedelta(hours=24), status=states.FAILURE
532+
).count()
533+
527534
return ctx

dataworkspace/dataworkspace/templates/admin/data_workspace_stats.html

+12
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,18 @@ <h3>In the past 7 days</h3>
189189
</a>
190190
</div>
191191
{% endif %}
192+
{% if failed_celery_tasks_24_hours is not None %}
193+
<div class="stat{% if failed_celery_tasks_24_hours > 0 %} bad-news{% endif %}">
194+
<a
195+
target="_blank"
196+
href="{% url 'admin:django_celery_results_taskresult_changelist' %}?status__exact=FAILURE"
197+
>
198+
<h2>Failed celery tasks</h2>
199+
<h1>{{ failed_celery_tasks_24_hours }}</h1>
200+
<h3>In the past 24 hours</h3>
201+
</a>
202+
</div>
203+
{% endif %}
192204
</div>
193205
{% if tool_start_chart_data is not None %}
194206
<h1>Tool start times</h1>

0 commit comments

Comments
 (0)