From fbbe3bdd9746d4236578a8efacf3f112633bf430 Mon Sep 17 00:00:00 2001 From: Lubos Kocman Date: Oct 17 2016 11:28:17 +0000 Subject: Add functionality to resume failed build - resume only failed module build tasks (this should be configurable in the future) Signed-off-by: Lubos Kocman --- diff --git a/rida/views.py b/rida/views.py index 2ddd7e1..1dc7b6e 100644 --- a/rida/views.py +++ b/rida/views.py @@ -122,21 +122,31 @@ class ModuleBuildAPI(MethodView): log.error('Invalid modulemd') raise UnprocessableEntity('Invalid modulemd') - if models.ModuleBuild.query.filter_by(name=mmd.name, + module = models.ModuleBuild.query.filter_by(name=mmd.name, version=mmd.version, - release=mmd.release).first(): - raise Conflict('Module already exists') - - module = models.ModuleBuild.create( - db.session, - conf, - name=mmd.name, - version=mmd.version, - release=mmd.release, - modulemd=yaml, - scmurl=url, - username=username - ) + release=mmd.release).first() + if module: + log.debug('Checking whether module build already exist.') + # TODO: make this configurable we might want to allow resubmit of any stucked build on DEV no matter the state + if module.state not in (models.BUILD_STATES['failed']): + log.error('Module (state=%s) already exists. Only new or failed builds are allowed.' % module.state) + raise Conflict('Module (state=%s) already exists. Only new or failed builds are allowed.' % module.state) + log.debug('Resuming existing module build %r' % module) + module.username = username + module.transition(conf, models.BUILD_STATES["init"]) + log.info("Resumed existing module build in previous state %s" % module.state) + else: + log.debug('Creating new module build') + module = models.ModuleBuild.create( + db.session, + conf, + name=mmd.name, + version=mmd.version, + release=mmd.release, + modulemd=yaml, + scmurl=url, + username=username + ) # List of (pkg_name, git_url) tuples to be used to check # the availability of git URLs paralelly later. @@ -182,13 +192,18 @@ class ModuleBuildAPI(MethodView): for pkgname, pkg in mmd.components.rpms.packages.items(): full_url = pkg["repository"] + "?#" + pkg["commit"] - build = models.ComponentBuild( - module_id=module.id, - package=pkgname, - format="rpms", - scmurl=full_url, - ) - db.session.add(build) + existing_build = models.ComponentBuild.query.filter_by(module_id=module.id, package=pkgname).first() + if existing_build and existing_build.state != models.BUILD_STATES['done']: + existing_build.state = models.BUILD_STATES['init'] + db.session.add(existing_build) + else: # XXX: what about components that were present in previous build but are gone now (component reduction) + build = models.ComponentBuild( + module_id=module.id, + package=pkgname, + format="rpms", + scmurl=full_url, + ) + db.session.add(build) module.modulemd = mmd.dumps() module.transition(conf, models.BUILD_STATES["wait"])