summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/toaster')
-rw-r--r--bitbake/lib/toaster/bldcontrol/migrations/0003_add_cancelling_state.py19
-rw-r--r--bitbake/lib/toaster/bldcontrol/models.py27
2 files changed, 45 insertions, 1 deletions
diff --git a/bitbake/lib/toaster/bldcontrol/migrations/0003_add_cancelling_state.py b/bitbake/lib/toaster/bldcontrol/migrations/0003_add_cancelling_state.py
new file mode 100644
index 0000000000..eec9216ca3
--- /dev/null
+++ b/bitbake/lib/toaster/bldcontrol/migrations/0003_add_cancelling_state.py
@@ -0,0 +1,19 @@
1# -*- coding: utf-8 -*-
2from __future__ import unicode_literals
3
4from django.db import migrations, models
5
6
7class Migration(migrations.Migration):
8
9 dependencies = [
10 ('bldcontrol', '0002_auto_20160120_1250'),
11 ]
12
13 operations = [
14 migrations.AlterField(
15 model_name='buildrequest',
16 name='state',
17 field=models.IntegerField(default=0, choices=[(0, b'created'), (1, b'queued'), (2, b'in progress'), (3, b'completed'), (4, b'failed'), (5, b'deleted'), (6, b'cancelling'), (7, b'archive')]),
18 ),
19 ]
diff --git a/bitbake/lib/toaster/bldcontrol/models.py b/bitbake/lib/toaster/bldcontrol/models.py
index 9b2d0d0b24..cb49a58c45 100644
--- a/bitbake/lib/toaster/bldcontrol/models.py
+++ b/bitbake/lib/toaster/bldcontrol/models.py
@@ -4,6 +4,8 @@ from django.core.validators import MaxValueValidator, MinValueValidator
4from django.utils.encoding import force_bytes 4from django.utils.encoding import force_bytes
5from orm.models import Project, ProjectLayer, ProjectVariable, ProjectTarget, Build, Layer_Version 5from orm.models import Project, ProjectLayer, ProjectVariable, ProjectTarget, Build, Layer_Version
6 6
7import logging
8logger = logging.getLogger("toaster")
7# a BuildEnvironment is the equivalent of the "build/" directory on the localhost 9# a BuildEnvironment is the equivalent of the "build/" directory on the localhost
8class BuildEnvironment(models.Model): 10class BuildEnvironment(models.Model):
9 SERVER_STOPPED = 0 11 SERVER_STOPPED = 0
@@ -64,7 +66,8 @@ class BuildRequest(models.Model):
64 REQ_COMPLETED = 3 66 REQ_COMPLETED = 3
65 REQ_FAILED = 4 67 REQ_FAILED = 4
66 REQ_DELETED = 5 68 REQ_DELETED = 5
67 REQ_ARCHIVE = 6 69 REQ_CANCELLING = 6
70 REQ_ARCHIVE = 7
68 71
69 REQUEST_STATE = ( 72 REQUEST_STATE = (
70 (REQ_CREATED, "created"), 73 (REQ_CREATED, "created"),
@@ -73,6 +76,7 @@ class BuildRequest(models.Model):
73 (REQ_COMPLETED, "completed"), 76 (REQ_COMPLETED, "completed"),
74 (REQ_FAILED, "failed"), 77 (REQ_FAILED, "failed"),
75 (REQ_DELETED, "deleted"), 78 (REQ_DELETED, "deleted"),
79 (REQ_CANCELLING, "cancelling"),
76 (REQ_ARCHIVE, "archive"), 80 (REQ_ARCHIVE, "archive"),
77 ) 81 )
78 82
@@ -85,6 +89,27 @@ class BuildRequest(models.Model):
85 created = models.DateTimeField(auto_now_add = True) 89 created = models.DateTimeField(auto_now_add = True)
86 updated = models.DateTimeField(auto_now = True) 90 updated = models.DateTimeField(auto_now = True)
87 91
92 def __init__(self, *args, **kwargs):
93 super(BuildRequest, self).__init__(*args, **kwargs)
94 # Save the old state incase it's about to be modified
95 self.old_state = self.state
96
97 def save(self, *args, **kwargs):
98 # Check that the state we're trying to set is not going backwards
99 # e.g. from REQ_FAILED to REQ_INPROGRESS
100 if self.old_state != self.state and self.old_state > self.state:
101 logger.warn("Invalid state change requested: "
102 "Cannot go from %s to %s - ignoring request" %
103 (BuildRequest.REQUEST_STATE[self.old_state][1],
104 BuildRequest.REQUEST_STATE[self.state][1])
105 )
106 # Set property back to the old value
107 self.state = self.old_state
108 return
109
110 super(BuildRequest, self).save(*args, **kwargs)
111
112
88 def get_duration(self): 113 def get_duration(self):
89 return (self.updated - self.created).total_seconds() 114 return (self.updated - self.created).total_seconds()
90 115