Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 036CDE00C52; Mon, 22 Feb 2016 03:31:46 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low * trust * [209.85.220.45 listed in list.dnswl.org] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily * valid * -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Received: from mail-pa0-f45.google.com (mail-pa0-f45.google.com [209.85.220.45]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id CEA42E00C75 for ; Mon, 22 Feb 2016 03:31:29 -0800 (PST) Received: by mail-pa0-f45.google.com with SMTP id yy13so89899434pab.3 for ; Mon, 22 Feb 2016 03:31:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=unDbrLwxKW6bS60YrJJBv+qHJwDu8P701oZR0ZoS9To=; b=B0Q0AnqUG/lDNoVg+uh/ZHI7QFs9+R+Pl/KaVLR4KbAket0czQIB39nq+j31/3nWTb 5SYn5nn4cCu4blXJrL+U9MHSCZ6MueAZELXfXa5YehltwumXUGPyz0ju0J0B8tlgBPnz /XatbBwqHchAWHvQ+AbGT8Mj1bFaoLQ2KdAlW9IU1//hXIIpasxQgaW9aepiqNlI3luv TosUKfYnHujRxkcBY67wZCNgqO+xpl/9fIE6ZLLv3KbzyqgKqns7+6bOaZIs/xK0R1dL EiRDH77bmwVOEAC/OId60QhPPEYgzLPU93cnlyKMdlONMmpMSvFbZWKzmpS+KXJhdMeC D1vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=unDbrLwxKW6bS60YrJJBv+qHJwDu8P701oZR0ZoS9To=; b=jjGYb5PzNxBIZiR4C5iXMCBgIMF4R7pXG01277SwvCd67EHNshHS12hUMxaitbrurL 5rItcGHuuVXwXkklXoMnWm5l/But0COB8z1j7VyU030PtvhLvzX2PbxiwM0C5wFZI4jw kORVm49iBWMI8fTDAyOybLA5U03RQXluOSA/iHZgG2kC3vE/vLNDXdC8GlG9V9F4abdQ 6+oAK5rQdEBO5IuVc5/xFXZm7MiDGq7iqEAmBtrrR20tRZo938nBWToGviZr1JDQZkiQ ohSCt9RE7t0egYMdOl3D2O2Z5P7VwCoAobcQWQF5tWzf+ZXccrRhOgUgztNQHeTrZDzL 88lQ== X-Gm-Message-State: AG10YOR9m/gMGSQH61lf+VSpBaVLdq3KTAalc12oEkRVWPmCOY6ZqIBGV3ArTpIBzqTlCfi3 X-Received: by 10.66.219.71 with SMTP id pm7mr37285820pac.137.1456140689085; Mon, 22 Feb 2016 03:31:29 -0800 (PST) Received: from dorado.ger.corp.intel.com (fmdmzpr01-ext.fm.intel.com. [192.55.54.36]) by smtp.gmail.com with ESMTPSA id n78sm36216801pfb.53.2016.02.22.03.31.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Feb 2016 03:31:28 -0800 (PST) From: Michael Wood To: toaster@yoctoproject.org Date: Mon, 22 Feb 2016 11:31:03 +0000 Message-Id: <1456140666-5344-8-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456140666-5344-1-git-send-email-michael.g.wood@intel.com> References: <1456140666-5344-1-git-send-email-michael.g.wood@intel.com> Subject: [PATCH 07/10] toaster: bldcontrol models Add a cancelling state the BuildRequest X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Feb 2016 11:31:46 -0000 To accurately reflect the state of a build request we also need a cancelling state. This is set when we've started a build and then for whatever reason cancel it, cancelling is not instantaneous so we have this state to indicate that a cancel is in progress. Also add a state transition guard. As the state of a BuildRequest can currently be modified by three processes; Toastergui, Runbuilds/bldcontrol and the buildinofhelper we cannot say for sure which process will be running at the time of cancellation so in order to avoid one of these processes making an incorrect transition only allow transitions of state to increase. e.g. CREATED -> QUEUED -> INPROGRESS And to ignore such requested changes such as INPROGRESS -> CREATED Signed-off-by: Michael Wood --- .../migrations/0002_add_cancelling_state.py | 19 +++++++++++++++ bitbake/lib/toaster/bldcontrol/models.py | 27 +++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 bitbake/lib/toaster/bldcontrol/migrations/0002_add_cancelling_state.py diff --git a/bitbake/lib/toaster/bldcontrol/migrations/0002_add_cancelling_state.py b/bitbake/lib/toaster/bldcontrol/migrations/0002_add_cancelling_state.py new file mode 100644 index 0000000..efcdf49 --- /dev/null +++ b/bitbake/lib/toaster/bldcontrol/migrations/0002_add_cancelling_state.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('bldcontrol', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='buildrequest', + name='state', + 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')]), + ), + ] diff --git a/bitbake/lib/toaster/bldcontrol/models.py b/bitbake/lib/toaster/bldcontrol/models.py index a3a49ce..0343ae9 100644 --- a/bitbake/lib/toaster/bldcontrol/models.py +++ b/bitbake/lib/toaster/bldcontrol/models.py @@ -2,6 +2,8 @@ from django.db import models from django.core.validators import MaxValueValidator, MinValueValidator from orm.models import Project, ProjectLayer, ProjectVariable, ProjectTarget, Build, Layer_Version +import logging +logger = logging.getLogger("toaster") # a BuildEnvironment is the equivalent of the "build/" directory on the localhost class BuildEnvironment(models.Model): SERVER_STOPPED = 0 @@ -60,7 +62,8 @@ class BuildRequest(models.Model): REQ_COMPLETED = 3 REQ_FAILED = 4 REQ_DELETED = 5 - REQ_ARCHIVE = 6 + REQ_CANCELLING = 6 + REQ_ARCHIVE = 7 REQUEST_STATE = ( (REQ_CREATED, "created"), @@ -69,6 +72,7 @@ class BuildRequest(models.Model): (REQ_COMPLETED, "completed"), (REQ_FAILED, "failed"), (REQ_DELETED, "deleted"), + (REQ_CANCELLING, "cancelling"), (REQ_ARCHIVE, "archive"), ) @@ -81,6 +85,27 @@ class BuildRequest(models.Model): created = models.DateTimeField(auto_now_add = True) updated = models.DateTimeField(auto_now = True) + def __init__(self, *args, **kwargs): + super(BuildRequest, self).__init__(*args, **kwargs) + # Save the old state incase it's about to be modified + self.old_state = self.state + + def save(self, *args, **kwargs): + # Check that the state we're trying to set is not going backwards + # e.g. from REQ_FAILED to REQ_INPROGRESS + if self.old_state != self.state and self.old_state > self.state: + logger.warn("Invalid state change requested: " + "Cannot go from %s to %s - ignoring request" % + (BuildRequest.REQUEST_STATE[self.old_state][1], + BuildRequest.REQUEST_STATE[self.state][1]) + ) + # Set property back to the old value + self.state = self.old_state + return + + super(BuildRequest, self).save(*args, **kwargs) + + def get_duration(self): return (self.updated - self.created).total_seconds() -- 2.5.0