Skip to content

#4036 Updated build list to include an alert state #5222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions media/css/core.css
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,14 @@ p.build-missing { font-size: .8em; color: #9d9a55; margin: 0 0 3px; }
#footer label { color: #BCC1C3; font-weight: normal; }
#footer input[type="text"], #footer input[type="email"] { padding: 4px; font-size: 12px; line-height: 16px; margin-bottom: 5px }

/* Warning Icon for Build List triggered */
.module-item.col-span a span.icon-warning:before {
font-family: FontAwesome;
font-size: .9em;
padding-right: .3em;
font-weight: normal;
content: "\f071";
}

/* utils */

Expand Down
8 changes: 8 additions & 0 deletions readthedocs/builds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

"""Models for the builds app."""

import datetime
import logging
import os.path
import re
Expand Down Expand Up @@ -32,6 +33,7 @@
BRANCH,
BUILD_STATE,
BUILD_STATE_FINISHED,
BUILD_STATE_TRIGGERED,
BUILD_TYPES,
LATEST,
NON_REPOSITORY_VERSIONS,
Expand Down Expand Up @@ -630,6 +632,12 @@ def finished(self):
"""Return if build has a finished state."""
return self.state == BUILD_STATE_FINISHED

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


class BuildCommandResultMixin:

Expand Down
31 changes: 31 additions & 0 deletions readthedocs/rtd_tests/tests/test_builds.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-
import datetime
import os

import mock
from django.test import TestCase
from django_dynamic_fixture import fixture, get
from django.utils import timezone

from readthedocs.builds.models import Build, Version
from readthedocs.doc_builder.config import load_yaml_config
Expand Down Expand Up @@ -531,3 +533,32 @@ def test_do_not_reference_empty_configs(self):
build_two.save()
self.assertEqual(build_two._config, {})
self.assertEqual(build_two.config, {})

def test_build_is_stale(self):
now = timezone.now()

build_one = get(
Build,
project=self.project,
version=self.version,
date=now - datetime.timedelta(minutes=8),
state='finished'
)
build_two = get(
Build,
project=self.project,
version=self.version,
date=now - datetime.timedelta(minutes=6),
state='triggered'
)
build_three = get(
Build,
project=self.project,
version=self.version,
date=now - datetime.timedelta(minutes=2),
state='triggered'
)

self.assertFalse(build_one.is_stale)
self.assertTrue(build_two.is_stale)
self.assertFalse(build_three.is_stale)
2 changes: 1 addition & 1 deletion readthedocs/templates/core/build_list_detailed.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% for build in build_qs %}
<li class="module-item col-span">
<div id="build-{{ build.id }}">
<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>
<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>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@humitos What Do you think about changing {% if build.state != 'finished' %} to {% if build.finished %} as already there is a property method on Build model named Build.finished? as @agjohnson mentioned to avoid logic on templates.

<img src="{% static 'core/img/loader.gif' %}" class="build-loading hide">
<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>
</a>
Expand Down