Skip to content

Commit 3218c80

Browse files
saadmk11agjohnson
authored andcommitted
readthedocs#4036 Updated build list to include an alert state (readthedocs#5222)
* Updated build list to include an alert state * Docstring issue fixed. * Template filter name changed. * Logic Moved to Models * Lint issue Fixed.
1 parent 5978dcf commit 3218c80

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

media/css/core.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,14 @@ p.build-missing { font-size: .8em; color: #9d9a55; margin: 0 0 3px; }
702702
#footer label { color: #BCC1C3; font-weight: normal; }
703703
#footer input[type="text"], #footer input[type="email"] { padding: 4px; font-size: 12px; line-height: 16px; margin-bottom: 5px }
704704

705+
/* Warning Icon for Build List triggered */
706+
.module-item.col-span a span.icon-warning:before {
707+
font-family: FontAwesome;
708+
font-size: .9em;
709+
padding-right: .3em;
710+
font-weight: normal;
711+
content: "\f071";
712+
}
705713

706714
/* utils */
707715

readthedocs/builds/models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
"""Models for the builds app."""
44

5+
import datetime
56
import logging
67
import os.path
78
import re
@@ -31,6 +32,7 @@
3132
BRANCH,
3233
BUILD_STATE,
3334
BUILD_STATE_FINISHED,
35+
BUILD_STATE_TRIGGERED,
3436
BUILD_TYPES,
3537
LATEST,
3638
NON_REPOSITORY_VERSIONS,
@@ -629,6 +631,12 @@ def finished(self):
629631
"""Return if build has a finished state."""
630632
return self.state == BUILD_STATE_FINISHED
631633

634+
@property
635+
def is_stale(self):
636+
"""Return if build state is triggered & date more than 5m ago."""
637+
mins_ago = timezone.now() - datetime.timedelta(minutes=5)
638+
return self.state == BUILD_STATE_TRIGGERED and self.date < mins_ago
639+
632640

633641
class BuildCommandResultMixin:
634642

readthedocs/rtd_tests/tests/test_builds.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# -*- coding: utf-8 -*-
2+
import datetime
23
import os
34

45
import mock
56
from django.test import TestCase
67
from django_dynamic_fixture import fixture, get
8+
from django.utils import timezone
79

810
from readthedocs.builds.models import Build, Version
911
from readthedocs.doc_builder.config import load_yaml_config
@@ -531,3 +533,32 @@ def test_do_not_reference_empty_configs(self):
531533
build_two.save()
532534
self.assertEqual(build_two._config, {})
533535
self.assertEqual(build_two.config, {})
536+
537+
def test_build_is_stale(self):
538+
now = timezone.now()
539+
540+
build_one = get(
541+
Build,
542+
project=self.project,
543+
version=self.version,
544+
date=now - datetime.timedelta(minutes=8),
545+
state='finished'
546+
)
547+
build_two = get(
548+
Build,
549+
project=self.project,
550+
version=self.version,
551+
date=now - datetime.timedelta(minutes=6),
552+
state='triggered'
553+
)
554+
build_three = get(
555+
Build,
556+
project=self.project,
557+
version=self.version,
558+
date=now - datetime.timedelta(minutes=2),
559+
state='triggered'
560+
)
561+
562+
self.assertFalse(build_one.is_stale)
563+
self.assertTrue(build_two.is_stale)
564+
self.assertFalse(build_three.is_stale)

readthedocs/templates/core/build_list_detailed.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{% for build in build_qs %}
55
<li class="module-item col-span">
66
<div id="build-{{ build.id }}">
7-
<a href="{{ build.get_absolute_url }}"><span id="build-state">{% if build.state != 'finished' %}{{ build.get_state_display }} {% else %} {% if build.success %}{% trans "Passed" %}{% else %}{% trans "Failed" %}{% endif %}{% endif %}</span>
7+
<a href="{{ build.get_absolute_url }}">{% if build.is_stale %}<span class="icon-warning" title="{% trans 'This build is still waiting to be built' %}"></span>{% endif %}<span id="build-state">{% if build.state != 'finished' %}{{ build.get_state_display }} {% else %} {% if build.success %}{% trans "Passed" %}{% else %}{% trans "Failed" %}{% endif %}{% endif %}</span>
88
<img src="{% static 'core/img/loader.gif' %}" class="build-loading hide">
99
<span class="quiet">{% if build.version %}{% blocktrans with build.version.slug as slug and build.type as type %}version {{ slug }} ({{ type }}){% endblocktrans %}{% endif %}</span><span class="quiet right">{% blocktrans with build.date|timesince as date %}{{ date }} ago{% endblocktrans %}</span>
1010
</a>

0 commit comments

Comments
 (0)