]> git.ipfire.org Git - people/jschlag/pbs.git/commitdiff
Add command to create test jobs
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 10 Oct 2017 16:58:39 +0000 (17:58 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 10 Oct 2017 16:59:25 +0000 (17:59 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/builds.py
src/buildservice/jobqueue.py
src/crontab/pakfire-build-service
src/manager/__init__.py
src/manager/builds.py
src/scripts/pakfire-build-service
src/scripts/pakfire-manager

index 03bc3fc8d4769658c58ec2ce1f09083103edf873..fae10329841556940774cbe3a3e84e90fafec97e 100644 (file)
@@ -225,36 +225,6 @@ class Builds(base.Object):
                if builds:
                        return builds.count
 
-       def needs_test(self, threshold, arch, limit=None, randomize=False):
-               query = "SELECT id FROM builds \
-                       WHERE NOT EXISTS \
-                               (SELECT * FROM jobs WHERE \
-                                       jobs.build_id = builds.id AND \
-                                       jobs.arch = %s AND \
-                                       (jobs.state != 'finished' OR \
-                                       jobs.time_finished >= %s) \
-                               ) \
-                       AND EXISTS \
-                               (SELECT * FROM jobs WHERE \
-                                       jobs.build_id = builds.id AND \
-                                       jobs.arch = %s AND \
-                                       jobs.type = 'build' AND \
-                                       jobs.state = 'finished' AND \
-                                       jobs.time_finished < %s \
-                               ) \
-                       AND builds.type = 'release' \
-                       AND (builds.state = 'stable' OR builds.state = 'testing')"
-               args  = [arch, threshold, arch, threshold]
-
-               if randomize:
-                       query += " ORDER BY RAND()"
-
-               if limit:
-                       query += " LIMIT %s"
-                       args.append(limit)
-
-               return [Build(self.pakfire, b.id) for b in self.db.query(query, *args)]
-
        def get_obsolete(self, repo=None):
                """
                        Get all obsoleted builds.
index 23f6d4fbbc3ddbd11254cfa192ef038a730c2f09..f8032719fed4587cdbb650bae80ba722be84b6cf 100644 (file)
@@ -1,7 +1,13 @@
 #!/usr/bin/python
 
+import datetime
+import logging
+
 from . import base
 
+log = logging.getLogger("jobqueue")
+log.propagate = 1
+
 PENDING_STATE = "pending"
 
 class JobQueue(base.Object):
@@ -38,4 +44,36 @@ class JobQueue(base.Object):
                res = self.db.get("SELECT AVG(NOW() - COALESCE(jobs.start_not_before, jobs.time_created)) AS avg \
                        FROM jobs_queue queue LEFT JOIN jobs ON queue.job_id = jobs.id")
 
-               return res.avg
\ No newline at end of file
+               return res.avg
+
+       def create_test_jobs(self):
+               max_queue_length = self.backend.settings.get_int("test_queue_limit", 25)
+
+               threshold_days = self.backend.settings.get_int("test_threshold_days", 14)
+               threshold = datetime.datetime.utcnow() - datetime.timedelta(days=threshold_days)
+
+               for arch in self.backend.arches:
+                       # Skip adding new jobs if there are more too many jobs in the queue.
+                       limit = max_queue_length - self.backend.jobqueue.get_length_for_arch(arch)
+                       if limit <= 0:
+                               log.debug("Already too many jobs in queue of %s to create tests." % arch)
+                               continue
+
+                       # Get a list of builds, with potentially need a test build.
+                       # Randomize the output and do not return more jobs than we are
+                       # allowed to put into the build queue.
+                       builds = self.backend.builds._get_builds("SELECT builds.* FROM builds \
+                               LEFT JOIN jobs ON builds.id = jobs.build_id \
+                               WHERE builds.type = %s AND builds.state = ANY(%s) AND jobs.state = %s \
+                                       AND NOT EXISTS (SELECT 1 FROM jobs test_jobs \
+                                               WHERE test_jobs.build_id = builds.id AND jobs.type = %s \
+                                                       AND (test_jobs.state <> %s OR test_jobs.state = %s AND test_jobs.time_finished >= %s)) LIMIT %s",
+                               "release", ["stable", "testing"], "finished", "test", "finished", "finished", threshold, limit)
+
+                       # Search for the job with the right architecture in each
+                       # build and schedule a test job.
+                       for build in builds:
+                               for job in build:
+                                       if job.arch == arch:
+                                               job.schedule("test")
+                                               break
index a4dc947b58bd273fc88d71c7f6f9757c2410bff8..d29b852e40da81c7d674aa7cf9c0060d57fed71d 100644 (file)
@@ -10,6 +10,9 @@
 # Send updates to Bugzilla
 */5 * * * *    nobody  pakfire-build-service send-bug-updates &>/dev/null
 
+# Create test jobs
+*/15 * * * *   nobody  pakfire-build-service create-test-jobs &>/dev/null
+
 # Cleanup files
 */5 * * * *    nobody  pakfire-build-service cleanup-files &>/dev/null
 
index fe248fe95928cfd2e9d2cdf10d61dc266a6dabe8..4a9b7354b25804ee5f67c03808a2d4adc8a47d3d 100644 (file)
@@ -1,4 +1,4 @@
 #!/usr/bin/python
 
 from .builds       import BuildsFailedRestartEvent, CheckBuildDependenciesEvent
-from .builds       import CreateTestBuildsEvent, DistEvent
+from .builds       import DistEvent
index a1a060431e38e19257164b340ecb0006d67b6879..9ff85d2bc58d8ca26d1433dd6919b04b5f9495cd 100644 (file)
@@ -92,48 +92,6 @@ class CheckBuildDependencyEvent(base.Event):
                job.resolvdep()
 
 
-class CreateTestBuildsEvent(base.Event):
-       # Run this every five minutes.
-       interval = 300
-
-       # Run when the build service is idle.
-       priority = 10
-
-       @property
-       def test_threshold(self):
-               threshold_days = self.pakfire.settings.get_int("test_threshold_days", 14)
-
-               return datetime.datetime.utcnow() - datetime.timedelta(days=threshold_days)
-
-       def run(self):
-               max_queue_length = self.pakfire.settings.get_int("test_queue_limit", 10)
-
-               for arch in self.backend.arches:
-                       # Skip adding new jobs if there are more too many jobs in the queue.
-                       limit = max_queue_length - self.backend.jobqueue.get_length_for_arch(arch)
-                       if limit <= 0:
-                               logging.debug("Already too many jobs in queue of %s to create tests." % arch)
-                               continue
-
-                       # Get a list of builds, with potentially need a test build.
-                       # Randomize the output and do not return more jobs than we are
-                       # allowed to put into the build queue.
-                       builds = self.pakfire.builds.needs_test(self.test_threshold,
-                               arch=arch, limit=limit)
-
-                       if not builds:
-                               logging.debug("No builds needs a test for %s." % arch.name)
-                               continue
-
-                       # Search for the job with the right architecture in each
-                       # build and schedule a test job.
-                       for build in builds:
-                               for job in build.jobs:
-                                       if job.arch == arch:
-                                               job.schedule("test")
-                                               break
-
-
 class DistEvent(base.Event):
        interval = 60
 
index 5ee79e73a7fad0d5bbbd9eda2e14a4fc73e8d6c0..470af173fc5c9ce26818cd9842171763c7bf676d 100644 (file)
@@ -26,6 +26,9 @@ class Cli(object):
                        # Cleanup uploads
                        "cleanup-uploads" : self.backend.uploads.cleanup,
 
+                       # Create test jobs
+                       "create-test-jobs" : self.backend.jobqueue.create_test_jobs,
+
                        # List repository
                        "list-repository" : self._list_repository,
 
index 81baed330994dac2ed82ae1cba636193e346611a..9e9dac8471f8c5bd4ad30e06c6e2c49ef2e69ebf 100644 (file)
@@ -18,7 +18,6 @@ p = pakfire.buildservice.Pakfire()
 events = (
        pakfire.buildservice.manager.BuildsFailedRestartEvent,
        pakfire.buildservice.manager.CheckBuildDependenciesEvent,
-       pakfire.buildservice.manager.CreateTestBuildsEvent,
        pakfire.buildservice.manager.DistEvent,
        pakfire.buildservice.manager.RepositoriesUpdateEvent,
 )