~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Raphael Badin
  • Date: 2012-01-06 08:27:55 UTC
  • mfrom: (14513.5.4 builder-history-lfa)
  • mto: This revision was merged to the branch mainline in revision 14654.
  • Revision ID: raphael.badin@canonical.com-20120106082755-95a0eh6nakv5hj3b
Merge devel.

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
69
70
from lp.services.helpers import filenameToContentType
70
71
from lp.services.job.interfaces.job import JobStatus
71
72
from lp.services.job.model.job import Job
549
550
 
550
551
    def setSlaveForTesting(self, proxy):
551
552
        """See IBuilder."""
 
553
        # XXX JeroenVermeulen 2011-11-09, bug=888010: Don't use this.
 
554
        # It's a trap.  See bug for details.
552
555
        self._testing_slave = proxy
553
556
        del get_property_cache(self).slave
554
557
 
677
680
                bytes_written = out_file.tell()
678
681
                out_file.seek(0)
679
682
 
680
 
                library_file = getUtility(ILibraryFileAliasSet).create(
681
 
                    filename, bytes_written, out_file,
682
 
                    contentType=filenameToContentType(filename),
683
 
                    restricted=private)
 
683
                transaction.commit()
 
684
                with DatabaseTransactionPolicy(read_only=False):
 
685
                    library_file = getUtility(ILibraryFileAliasSet).create(
 
686
                        filename, bytes_written, out_file,
 
687
                        contentType=filenameToContentType(filename),
 
688
                        restricted=private)
 
689
                    transaction.commit()
684
690
            finally:
685
691
                # Remove the temporary file.  getFile() closes the file
686
692
                # object.
718
724
    def acquireBuildCandidate(self):
719
725
        """Acquire a build candidate in an atomic fashion.
720
726
 
721
 
        When retrieiving a candidate we need to mark it as building
 
727
        When retrieving a candidate we need to mark it as building
722
728
        immediately so that it is not dispatched by another builder in the
723
729
        build manager.
724
730
 
728
734
        can be in this code at the same time.
729
735
 
730
736
        If there's ever more than one build manager running at once, then
731
 
        this code will need some sort of mutex.
 
737
        this code will need some sort of mutex, or run in a single
 
738
        transaction.
732
739
        """
733
740
        candidate = self._findBuildCandidate()
734
741
        if candidate is not None:
735
 
            candidate.markAsBuilding(self)
736
742
            transaction.commit()
 
743
            with DatabaseTransactionPolicy(read_only=False):
 
744
                candidate.markAsBuilding(self)
 
745
                transaction.commit()
737
746
        return candidate
738
747
 
739
748
    def _findBuildCandidate(self):
796
805
        store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR)
797
806
        candidate_jobs = store.execute(query).get_all()
798
807
 
799
 
        for (candidate_id,) in candidate_jobs:
800
 
            candidate = getUtility(IBuildQueueSet).get(candidate_id)
801
 
            job_class = job_classes[candidate.job_type]
802
 
            candidate_approved = job_class.postprocessCandidate(
803
 
                candidate, logger)
804
 
            if candidate_approved:
805
 
                return candidate
 
808
        transaction.commit()
 
809
        with DatabaseTransactionPolicy(read_only=False):
 
810
            for (candidate_id,) in candidate_jobs:
 
811
                candidate = getUtility(IBuildQueueSet).get(candidate_id)
 
812
                job_class = job_classes[candidate.job_type]
 
813
                candidate_approved = job_class.postprocessCandidate(
 
814
                    candidate, logger)
 
815
                if candidate_approved:
 
816
                    transaction.commit()
 
817
                    return candidate
 
818
            transaction.commit()
806
819
 
807
820
        return None
808
821