]> git.ipfire.org Git - pbs.git/commitdiff
jobs: Implement marking jobs as aborted
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Oct 2022 19:43:28 +0000 (19:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Oct 2022 19:43:28 +0000 (19:43 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/jobs.py
src/database.sql

index 32f25a4f889a529bdd5f5e838ce91f94eae4d9f2..e05d2b94b0f5974863b018659cc21b459b76fc2b 100644 (file)
@@ -327,7 +327,28 @@ class Job(base.DataObject):
                """
                        Aborts the job
                """
-               pass # XXX TODO
+               # Mark as aborted
+               self._set_attribute_now("aborted_at")
+               if user:
+                       self._set_attribute("aborted_by", user)
+
+       def is_aborted(self):
+               """
+                       Returns True if this job has been aborted
+               """
+               if self.aborted_at:
+                       return True
+
+               return False
+
+       @property
+       def aborted_at(self):
+               return self.data.aborted_at
+
+       @lazy_property
+       def aborted_by(self):
+               if self.data.aborted_by:
+                       return self.backend.users.get_by_id(self.data.aborted_by)
 
        @property
        def message(self):
index a6f2b863ec0ffe7051efae3228a719dc8e9b7731..b6a0162d447d67dfbf8fb751725580b4ddb6201a 100644 (file)
@@ -342,7 +342,9 @@ CREATE TABLE public.jobs (
     log_size bigint,
     log_digest_blake2s bytea,
     deleted_at timestamp without time zone,
-    deleted_by integer
+    deleted_by integer,
+    aborted_at timestamp without time zone,
+    aborted_by integer
 );
 
 
@@ -1749,6 +1751,14 @@ ALTER TABLE ONLY public.builds
     ADD CONSTRAINT builds_pkg_id FOREIGN KEY (pkg_id) REFERENCES public.packages(id);
 
 
+--
+-- Name: jobs jobs_aborted_by; Type: FK CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.jobs
+    ADD CONSTRAINT jobs_aborted_by FOREIGN KEY (aborted_by) REFERENCES public.users(id);
+
+
 --
 -- Name: jobs jobs_build_id; Type: FK CONSTRAINT; Schema: public; Owner: -
 --