From 96cc81de65372a61624fa095c5fbe8ee2511e925 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 21 Oct 2017 15:59:02 +0100 Subject: [PATCH] jobs: Create a copy of an existing job when restarting Signed-off-by: Michael Tremer --- src/buildservice/jobs.py | 19 ++++++++++++------- src/database.sql | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/buildservice/jobs.py b/src/buildservice/jobs.py index 604b4d0..380a1ee 100644 --- a/src/buildservice/jobs.py +++ b/src/buildservice/jobs.py @@ -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. diff --git a/src/database.sql b/src/database.sql index 7465f64..61d3b7a 100644 --- a/src/database.sql +++ b/src/database.sql @@ -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, -- 2.47.3