Skip to content

Commit 740c75b

Browse files
committed
Merge pull request #1577 from rtfd/build-failure-email
Fix email notifications on build failures
2 parents 141ebf0 + a5be71f commit 740c75b

File tree

5 files changed

+41
-17
lines changed

5 files changed

+41
-17
lines changed

readthedocs/projects/tasks.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ def run(self, pk, version_pk=None, build_pk=None, record=True, docker=False,
142142
epub=outcomes['epub'],
143143
)
144144

145+
if self.build_env.failed:
146+
self.send_notifications()
147+
145148
@staticmethod
146149
def get_project(project_pk):
147150
"""
@@ -424,6 +427,10 @@ def build_docs_class(self, builder_class):
424427
builder.move()
425428
return success
426429

430+
def send_notifications(self):
431+
"""Send notifications on build failure"""
432+
send_notifications.delay(self.version.pk, build_pk=self.build['id'])
433+
427434

428435
update_docs = celery_app.tasks[UpdateDocsTask.name]
429436

@@ -543,8 +550,6 @@ def finish_build(version_pk, build_pk, hostname=None, html=False,
543550
update_static_metadata.delay(version.project.pk)
544551
fileify.delay(version.pk, commit=build.commit)
545552
update_search.delay(version.pk, commit=build.commit)
546-
if not html and version.slug != STABLE and build.exit_code != 423:
547-
send_notifications.delay(version.pk, build_pk=build.pk)
548553

549554

550555
@task(queue='web')

readthedocs/rtd_tests/mocks/mock_api.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,20 @@ def __init__(self, repo):
7777
def project(self, x):
7878
return ProjectData()
7979

80+
def build(self, x):
81+
return mock.Mock(**{'get.return_value': {'state': 'triggered'}})
82+
83+
def command(self, x):
84+
return mock.Mock(**{'get.return_value': {}})
85+
8086

8187
@contextmanager
8288
def mock_api(repo):
8389
api_mock = MockApi(repo)
84-
with (
85-
mock.patch('readthedocs.restapi.client.api', api_mock) and
86-
mock.patch('readthedocs.api.client.api', api_mock) and
87-
mock.patch('readthedocs.projects.tasks.api_v2', api_mock) and
88-
mock.patch('readthedocs.projects.tasks.api_v1', api_mock)):
90+
with mock.patch('readthedocs.restapi.client.api', api_mock), \
91+
mock.patch('readthedocs.api.client.api', api_mock), \
92+
mock.patch('readthedocs.projects.tasks.api_v2', api_mock), \
93+
mock.patch('readthedocs.projects.tasks.api_v1', api_mock), \
94+
mock.patch('readthedocs.doc_builder.environments.api_v1', api_mock), \
95+
mock.patch('readthedocs.doc_builder.environments.api_v2', api_mock):
8996
yield api_mock

readthedocs/rtd_tests/tests/test_celery.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
from tempfile import mkdtemp
66

77
from django.contrib.auth.models import User
8+
from django_dynamic_fixture import get
89
from mock import patch, MagicMock
910

11+
from readthedocs.builds.models import Build
1012
from readthedocs.projects.models import Project
1113
from readthedocs.projects import tasks
1214

@@ -66,10 +68,14 @@ def test_clear_artifacts(self):
6668
@patch('readthedocs.projects.tasks.UpdateDocsTask.setup_vcs',
6769
new=MagicMock)
6870
def test_update_docs(self):
69-
with mock_api(self.repo):
70-
update_docs = tasks.UpdateDocsTask()
71-
result = update_docs.delay(self.project.pk, record=False,
72-
intersphinx=False)
71+
build = get(Build, project=self.project,
72+
version=self.project.versions.first())
73+
with mock_api(self.repo) as mapi:
74+
result = tasks.update_docs.delay(
75+
self.project.pk,
76+
build_pk=build.pk,
77+
record=False,
78+
intersphinx=False)
7379
self.assertTrue(result.successful())
7480

7581
def test_update_imported_doc(self):

readthedocs/templates/projects/email/build_failed.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@
99
{% endblock %}
1010

1111
{% block content %}
12+
{% if build.error %}
13+
<p>
14+
Error: {{ build.error }}
15+
</p>
16+
{% endif %}
17+
1218
<p>
13-
You can see what went wrong here:
19+
You can find out more about this failure here:
1420
</p>
1521

1622
<p>

readthedocs/templates/projects/email/build_failed.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{% extends "core/email/common.txt" %}
22
{% block salutation %}Build Failed for {{ project.name }} ({{ version.verbose_name }}){% endblock %}
33
{% block content %}
4-
5-
6-
7-
8-
You can see what went wrong here:
4+
{% if build.error %}
5+
Error:
6+
{{ build.error }}
7+
{% endif %}
8+
You can find out more about this failure here:
99
{{ build_url }}
1010

1111
If you have questions, a good place to start is the FAQ:

0 commit comments

Comments
 (0)