]> git.ipfire.org Git - people/jschlag/pbs.git/commitdiff
jobs: Create a copy of an existing job when restarting
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 21 Oct 2017 14:59:02 +0000 (15:59 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 21 Oct 2017 14:59:02 +0000 (15:59 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/jobs.py
src/database.sql

index 604b4d0fe5507a29db7a03c3a9dc10deb5a97ea2..380a1eec459097b6443da6bdf0ef2aa7be21fde3 100644 (file)
@@ -34,9 +34,9 @@ class Jobs(base.Object):
                for row in res:
                        yield Job(self.backend, row.id, data=row)
 
-       def create(self, build, arch, type="build", superseeds=None):
-               job = self._get_job("INSERT INTO jobs(uuid, type, build_id, arch, time_created) \
-                       VALUES(%s, %s, %s, %s, NOW()) RETURNING *", "%s" % uuid.uuid4(), type, build.id, arch)
+       def create(self, build, arch, test=False superseeds=None):
+               job = self._get_job("INSERT INTO jobs(uuid, build_id, arch, test) \
+                       VALUES(%s, %s, %s, %s) RETURNING *", "%s" % uuid.uuid4(), build.id, arch, test)
                job.log("created")
 
                # Set cache for Build object.
@@ -193,7 +193,7 @@ class Jobs(base.Object):
 
                # Restart the job
                for job in jobs:
-                       job.set_state("new", log=False)
+                       job.restart()
 
 
 class Job(base.DataObject):
@@ -236,6 +236,11 @@ class Job(base.DataObject):
        def distro(self):
                return self.build.distro
 
+       def restart(self):
+               # Copy the job and let it build again
+               return self.backend.jobs.create(self.build, self.arch,
+                       test=self.test, superseeds=self)
+
        def get_superseeded_by(self):
                if self.data.superseeded_by:
                        return self.backend.jobs.get_by_id(self.data.superseeded_by)
@@ -718,8 +723,8 @@ class Job(base.DataObject):
                        if self.state == "finished":
                                return
 
-                       self.set_state("new", user=user, log=False)
-                       self.set_start_time(start_time)
+                       job = self.restart()
+                       job.set_start_time(start_time)
 
                        # Log the event.
                        self.log("schedule_rebuild", user=user)
@@ -729,7 +734,7 @@ class Job(base.DataObject):
                                return
 
                        # Create a new job with same build and arch.
-                       job = self.create(self.backend, self.build, self.arch, type="test")
+                       job = self.create(self.backend, self.build, self.arch, test=True)
                        job.set_start_time(start_time)
 
                        # Log the event.
index 7465f642640c23356d82961aeae91b82ee8c59f4..61d3b7a988b1587cad3a2893dea9362c1ea8efd0 100644 (file)
@@ -857,7 +857,7 @@ CREATE TABLE jobs (
     build_id integer NOT NULL,
     state jobs_state DEFAULT 'new'::jobs_state NOT NULL,
     arch text NOT NULL,
-    time_created timestamp without time zone NOT NULL,
+    time_created timestamp without time zone DEFAULT now() NOT NULL,
     time_started timestamp without time zone,
     time_finished timestamp without time zone,
     start_not_before timestamp without time zone,