~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/buildmaster/model/buildfarmjob.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-11-21 21:25:38 UTC
  • mfrom: (14348.1.1 relatedjobs-bug-891600)
  • Revision ID: launchpad@pqm.canonical.com-20111121212538-azocog20hyqze6d2
[r=benji][bug=891600] Fix BuildFarmJobSet.getSpecificJobs to handle
        duplicate jobs correctly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
    )
71
71
from lp.buildmaster.interfaces.buildqueue import IBuildQueueSet
72
72
from lp.registry.model.teammembership import TeamParticipation
 
73
from lp.soyuz.interfaces.binarypackagebuild import IBinaryPackageBuildSet
73
74
 
74
75
 
75
76
class BuildFarmJobOld:
404
405
        builds = []
405
406
        key = attrgetter('job_type.name')
406
407
        sorted_jobs = sorted(jobs, key=key)
 
408
        job_builds = {}
407
409
        for job_type_name, grouped_jobs in groupby(sorted_jobs, key=key):
408
410
            # Fetch the jobs in batches grouped by their job type.
409
411
            source = getUtility(
410
412
                ISpecificBuildFarmJobSource, job_type_name)
411
 
            builds.extend(
412
 
                [build for build
413
 
                    in source.getByBuildFarmJobs(list(grouped_jobs))
414
 
                    if build is not None])
415
 
        # Make sure that all the specific jobs have been found.
416
 
        if len(jobs) != len(builds):
 
413
            builds = [build for build
 
414
                in source.getByBuildFarmJobs(list(grouped_jobs))
 
415
                if build is not None]
 
416
            is_binary_package_build = IBinaryPackageBuildSet.providedBy(
 
417
                source)
 
418
            for build in builds:
 
419
                if is_binary_package_build:
 
420
                    job_builds[build.package_build.build_farm_job.id] = build
 
421
                else:
 
422
                    job_builds[build.build_farm_job.id] = build
 
423
        # Return the corresponding builds.
 
424
        try:
 
425
            return [job_builds[job.id] for job in jobs]
 
426
        except KeyError:
417
427
            raise InconsistentBuildFarmJobError(
418
428
                "Could not find all the related specific jobs.")
419
 
        # Sort the builds to match the jobs' order.
420
 
        sorted_builds = sorted(
421
 
            builds,
422
 
            key=lambda build: list(jobs).index(build.build_farm_job))
423
 
        return sorted_builds
424
429
 
425
430
    def getBuildsForBuilder(self, builder_id, status=None, user=None):
426
431
        """See `IBuildFarmJobSet`."""