~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2012-01-04 16:24:40 UTC
  • mfrom: (8758.7.4 garbo-bulk-pruner)
  • Revision ID: launchpad@pqm.canonical.com-20120104162440-jy34l21i0bcirh1z
[r=wgrant][no-qa] Trash EmailAddress and Account records not linked
        to a Person.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2009,2011 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
# pylint: disable-msg=E0611,W0212
66
66
    SQLBase,
67
67
    sqlvalues,
68
68
    )
69
 
from lp.services.database.transaction_policy import DatabaseTransactionPolicy
70
69
from lp.services.helpers import filenameToContentType
71
70
from lp.services.job.interfaces.job import JobStatus
72
71
from lp.services.job.model.job import Job
546
545
 
547
546
    def setSlaveForTesting(self, proxy):
548
547
        """See IBuilder."""
549
 
        # XXX JeroenVermeulen 2011-11-09, bug=888010: Don't use this.
550
 
        # It's a trap.  See bug for details.
551
548
        self._testing_slave = proxy
552
549
        del get_property_cache(self).slave
553
550
 
676
673
                bytes_written = out_file.tell()
677
674
                out_file.seek(0)
678
675
 
679
 
                transaction.commit()
680
 
                with DatabaseTransactionPolicy(read_only=False):
681
 
                    library_file = getUtility(ILibraryFileAliasSet).create(
682
 
                        filename, bytes_written, out_file,
683
 
                        contentType=filenameToContentType(filename),
684
 
                        restricted=private)
685
 
                    transaction.commit()
 
676
                library_file = getUtility(ILibraryFileAliasSet).create(
 
677
                    filename, bytes_written, out_file,
 
678
                    contentType=filenameToContentType(filename),
 
679
                    restricted=private)
686
680
            finally:
687
681
                # Remove the temporary file.  getFile() closes the file
688
682
                # object.
720
714
    def acquireBuildCandidate(self):
721
715
        """Acquire a build candidate in an atomic fashion.
722
716
 
723
 
        When retrieving a candidate we need to mark it as building
 
717
        When retrieiving a candidate we need to mark it as building
724
718
        immediately so that it is not dispatched by another builder in the
725
719
        build manager.
726
720
 
730
724
        can be in this code at the same time.
731
725
 
732
726
        If there's ever more than one build manager running at once, then
733
 
        this code will need some sort of mutex, or run in a single
734
 
        transaction.
 
727
        this code will need some sort of mutex.
735
728
        """
736
729
        candidate = self._findBuildCandidate()
737
730
        if candidate is not None:
 
731
            candidate.markAsBuilding(self)
738
732
            transaction.commit()
739
 
            with DatabaseTransactionPolicy(read_only=False):
740
 
                candidate.markAsBuilding(self)
741
 
                transaction.commit()
742
733
        return candidate
743
734
 
744
735
    def _findBuildCandidate(self):
801
792
        store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR)
802
793
        candidate_jobs = store.execute(query).get_all()
803
794
 
804
 
        transaction.commit()
805
 
        with DatabaseTransactionPolicy(read_only=False):
806
 
            for (candidate_id,) in candidate_jobs:
807
 
                candidate = getUtility(IBuildQueueSet).get(candidate_id)
808
 
                job_class = job_classes[candidate.job_type]
809
 
                candidate_approved = job_class.postprocessCandidate(
810
 
                    candidate, logger)
811
 
                if candidate_approved:
812
 
                    transaction.commit()
813
 
                    return candidate
814
 
            transaction.commit()
 
795
        for (candidate_id,) in candidate_jobs:
 
796
            candidate = getUtility(IBuildQueueSet).get(candidate_id)
 
797
            job_class = job_classes[candidate.job_type]
 
798
            candidate_approved = job_class.postprocessCandidate(
 
799
                candidate, logger)
 
800
            if candidate_approved:
 
801
                return candidate
815
802
 
816
803
        return None
817
804