Skip to content

Commit aef1f6b

Browse files
authored
Merge pull request #1 from teamhephy/feature/exceptions-on-release-api
Adding exception field on release api
2 parents 73f7e9e + 44684d5 commit aef1f6b

5 files changed

Lines changed: 28 additions & 1 deletion

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.2 on 2017-08-28 14:59
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('api', '0025_app_procfile_structure'),
12+
]
13+
14+
operations = [
15+
migrations.AddField(
16+
model_name='release',
17+
name='exception',
18+
field=models.TextField(blank=True, null=True),
19+
),
20+
]

rootfs/api/models/build.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def create(self, user, *args, **kwargs):
7272
if 'new_release' in locals():
7373
new_release.failed = True
7474
new_release.summary = "{} deployed {} which failed".format(self.owner, str(self.uuid)[:7]) # noqa
75+
# Get the exception that has occured
76+
new_release.exception = "error: {}".format(str(e))
7577
new_release.save()
7678
else:
7779
self.delete()

rootfs/api/models/release.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Release(UuidAuditedModel):
2424
version = models.PositiveIntegerField()
2525
summary = models.TextField(blank=True, null=True)
2626
failed = models.BooleanField(default=False)
27+
exception = models.TextField(blank=True, null=True)
2728

2829
config = models.ForeignKey('Config', on_delete=models.CASCADE)
2930
build = models.ForeignKey('Build', null=True, on_delete=models.CASCADE)
@@ -243,6 +244,8 @@ def rollback(self, user, version=None):
243244
if 'new_release' in locals():
244245
new_release.failed = True
245246
new_release.summary = "{} performed roll back to a release that failed".format(self.owner) # noqa
247+
# Get the exception that has occured
248+
new_release.exception = "error: {}".format(str(e))
246249
new_release.save()
247250
raise DeisException(str(e)) from e
248251

rootfs/api/tests/test_release.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_response_data(self, mock_requests):
114114
response = self.client.get(url)
115115
for key in response.data.keys():
116116
self.assertIn(key, ['uuid', 'owner', 'created', 'updated', 'app', 'build', 'config',
117-
'summary', 'version', 'failed'])
117+
'summary', 'version', 'failed', 'exception'])
118118
expected = {
119119
'owner': self.user.username,
120120
'app': app_id,

rootfs/api/views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ def post_save(self, config):
289289
if hasattr(self, 'release'):
290290
self.release.failed = True
291291
self.release.summary = "{} deployed a config that failed".format(self.request.user) # noqa
292+
# Get the exception that has occured
293+
self.release.exception = "error: {}".format(str(e))
292294
self.release.save()
293295
else:
294296
config.delete()

0 commit comments

Comments
 (0)