"""
log.debug("Running autoscaling schedulder")
- # XXX max queue length
- threshold = datetime.timedelta(minutes=5)
-
builders = {}
# Fetch all builders and their value for sorting
# Store the length of the queue for each builder
queue = {
- builder : datetime.timedelta(0) for builder in builders
+ builder : 0 for builder in builders
}
# Run through all build jobs and allocate them to a builder.
continue
# Check if this builder is already at capacity
- if queue[builder] / builder.max_jobs >= threshold:
+ if queue[builder] >= builder.max_jobs:
log.debug("Builder %s is already full" % builder)
continue
log.debug("Builder %s can build %s" % (builder, job))
- # Add the job to the total build time
- queue[builder] += job.estimated_build_time or datetime.timedelta(60)
+ # Store the job
+ queue[builder] += 1
break
# Find all builders that should be running
def size(self):
return sum((p.size for p in self.packages))
- @lazy_property
- def estimated_build_time(self):
- """
- Returns the time we expect this job to run for
- """
- res = self.db.get("""
- WITH package_estimated_build_times AS (
- SELECT
- packages.name,
- jobs.arch,
- AVG(
- jobs.finished_at - jobs.started_at
- ) AS build_time
- FROM
- jobs
- LEFT JOIN
- builds ON jobs.build_id = builds.id
- LEFT JOIN
- packages ON builds.pkg_id = packages.id
- WHERE
- jobs.deleted_at IS NULL
- AND
- jobs.started_at IS NOT NULL
- AND
- jobs.finished_at IS NOT NULL
- AND
- jobs.failed IS FALSE
- AND
- builds.test IS FALSE
- AND
- jobs.finished_at >= (CURRENT_TIMESTAMP - '180 days'::interval)
- GROUP BY
- packages.name,
- jobs.arch
- )
-
- SELECT
- build_time
- FROM
- package_estimated_build_times
- WHERE
- name = %s
- AND
- arch = %s""",
- self.pkg.name, self.arch,
- )
-
- if res:
- return res.build_time
-
# Distro
@property