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.
#!/usr/bin/python
+import datetime
+import logging
+
from . import base
+log = logging.getLogger("jobqueue")
+log.propagate = 1
+
PENDING_STATE = "pending"
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
# 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
#!/usr/bin/python
from .builds import BuildsFailedRestartEvent, CheckBuildDependenciesEvent
-from .builds import CreateTestBuildsEvent, DistEvent
+from .builds import DistEvent
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
# 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,
events = (
pakfire.buildservice.manager.BuildsFailedRestartEvent,
pakfire.buildservice.manager.CheckBuildDependenciesEvent,
- pakfire.buildservice.manager.CreateTestBuildsEvent,
pakfire.buildservice.manager.DistEvent,
pakfire.buildservice.manager.RepositoriesUpdateEvent,
)