Skip to content

Fix email notifications on build failures #1577

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 3 commits into from
Aug 20, 2015
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
9 changes: 7 additions & 2 deletions readthedocs/projects/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ def run(self, pk, version_pk=None, build_pk=None, record=True, docker=False,
epub=outcomes['epub'],
)

if self.build_env.failed:
self.send_notifications()

@staticmethod
def get_project(project_pk):
"""
Expand Down Expand Up @@ -424,6 +427,10 @@ def build_docs_class(self, builder_class):
builder.move()
return success

def send_notifications(self):
"""Send notifications on build failure"""
send_notifications.delay(self.version.pk, build_pk=self.build['id'])


update_docs = celery_app.tasks[UpdateDocsTask.name]

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


@task(queue='web')
Expand Down
17 changes: 12 additions & 5 deletions readthedocs/rtd_tests/mocks/mock_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,20 @@ def __init__(self, repo):
def project(self, x):
return ProjectData()

def build(self, x):
return mock.Mock(**{'get.return_value': {'state': 'triggered'}})

def command(self, x):
return mock.Mock(**{'get.return_value': {}})


@contextmanager
def mock_api(repo):
api_mock = MockApi(repo)
with (
mock.patch('readthedocs.restapi.client.api', api_mock) and
mock.patch('readthedocs.api.client.api', api_mock) and
mock.patch('readthedocs.projects.tasks.api_v2', api_mock) and
mock.patch('readthedocs.projects.tasks.api_v1', api_mock)):
with mock.patch('readthedocs.restapi.client.api', api_mock), \
mock.patch('readthedocs.api.client.api', api_mock), \
mock.patch('readthedocs.projects.tasks.api_v2', api_mock), \
mock.patch('readthedocs.projects.tasks.api_v1', api_mock), \
mock.patch('readthedocs.doc_builder.environments.api_v1', api_mock), \
mock.patch('readthedocs.doc_builder.environments.api_v2', api_mock):
yield api_mock
14 changes: 10 additions & 4 deletions readthedocs/rtd_tests/tests/test_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
from tempfile import mkdtemp

from django.contrib.auth.models import User
from django_dynamic_fixture import get
from mock import patch, MagicMock

from readthedocs.builds.models import Build
from readthedocs.projects.models import Project
from readthedocs.projects import tasks

Expand Down Expand Up @@ -66,10 +68,14 @@ def test_clear_artifacts(self):
@patch('readthedocs.projects.tasks.UpdateDocsTask.setup_vcs',
new=MagicMock)
def test_update_docs(self):
with mock_api(self.repo):
update_docs = tasks.UpdateDocsTask()
result = update_docs.delay(self.project.pk, record=False,
intersphinx=False)
build = get(Build, project=self.project,
version=self.project.versions.first())
with mock_api(self.repo) as mapi:
result = tasks.update_docs.delay(
self.project.pk,
build_pk=build.pk,
record=False,
intersphinx=False)
self.assertTrue(result.successful())

def test_update_imported_doc(self):
Expand Down
8 changes: 7 additions & 1 deletion readthedocs/templates/projects/email/build_failed.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
{% endblock %}

{% block content %}
{% if build.error %}
<p>
Error: {{ build.error }}
</p>
{% endif %}

<p>
You can see what went wrong here:
You can find out more about this failure here:
</p>

<p>
Expand Down
10 changes: 5 additions & 5 deletions readthedocs/templates/projects/email/build_failed.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{% extends "core/email/common.txt" %}
{% block salutation %}Build Failed for {{ project.name }} ({{ version.verbose_name }}){% endblock %}
{% block content %}




You can see what went wrong here:
{% if build.error %}
Error:
{{ build.error }}
{% endif %}
You can find out more about this failure here:
{{ build_url }}

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