From: Michael Tremer Date: Fri, 27 Oct 2017 16:32:08 +0000 (+0100) Subject: Get active jobs from an index as well X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de667c37c40b6a5e18081d407907cfece38f8a1b;p=pbs.git Get active jobs from an index as well Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/jobs.py b/src/buildservice/jobs.py index 7810891e..fd9e98bb 100644 --- a/src/buildservice/jobs.py +++ b/src/buildservice/jobs.py @@ -54,29 +54,12 @@ class Jobs(base.Object): def get_by_uuid(self, uuid): return self._get_job("SELECT * FROM jobs WHERE uuid = %s", uuid) - def get_active(self, host_id=None, builder=None, states=None): - if builder: - host_id = builder.id - - if states is None: - states = ["dispatching", "running", "uploading"] - - query = "SELECT * FROM jobs WHERE state IN (%s)" % ", ".join(["%s"] * len(states)) - args = states - - if host_id: - query += " AND builder_id = %s" % host_id - - query += " ORDER BY \ - CASE \ - WHEN jobs.state = 'running' THEN 0 \ - WHEN jobs.state = 'uploading' THEN 1 \ - WHEN jobs.state = 'dispatching' THEN 2 \ - WHEN jobs.state = 'pending' THEN 3 \ - WHEN jobs.state = 'new' THEN 4 \ - END, time_started ASC" + def get_active(self, limit=None): + jobs = self._get_jobs("SELECT jobs.* FROM jobs \ + WHERE time_started IS NOT NULL AND time_finished IS NULL \ + ORDER BY time_started LIMIT %s", limit) - return [Job(self.backend, j.id, j) for j in self.db.query(query, *args)] + return jobs def get_recently_ended(self, limit=None): jobs = self._get_jobs("SELECT jobs.* FROM jobs \ diff --git a/src/database.sql b/src/database.sql index f0784e68..92ac3654 100644 --- a/src/database.sql +++ b/src/database.sql @@ -2604,6 +2604,13 @@ CREATE INDEX jobs_buildroots_pkg_uuid ON jobs_buildroots USING btree (pkg_uuid); CREATE INDEX jobs_time_finished ON jobs USING btree (time_finished DESC) WHERE (time_finished IS NOT NULL); +-- +-- Name: jobs_time_started; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: +-- + +CREATE INDEX jobs_time_started ON jobs USING btree (time_started) WHERE ((time_started IS NOT NULL) AND (time_finished IS NULL)); + + -- -- Name: mirrors_checks_sort; Type: INDEX; Schema: public; Owner: pakfire; Tablespace: -- diff --git a/src/web/handlers.py b/src/web/handlers.py index cc42a5a7..0f5250b7 100644 --- a/src/web/handlers.py +++ b/src/web/handlers.py @@ -6,7 +6,12 @@ from . import base class IndexHandler(base.BaseHandler): def get(self): - jobs = self.backend.jobs.get_active() + jobs = [] + + # Get all active jobs + jobs += self.backend.jobs.get_active() + + # Get some recently finished jobs jobs += self.backend.jobs.get_recently_ended(limit=12) # Updates