~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: 2011-12-09 07:52:37 UTC
  • mfrom: (14047.3.42 bug-717969)
  • Revision ID: launchpad@pqm.canonical.com-20111209075237-4u2pxpo653uecm4i
[r=bigjools][bug=717969] Read-only transactions by default in
 buildmaster.

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
76
76
    specific_job_classes,
77
77
    )
78
78
from lp.registry.interfaces.person import validate_public_person
 
79
from lp.services.database.transaction_policy import DatabaseTransactionPolicy
79
80
from lp.services.job.interfaces.job import JobStatus
80
81
from lp.services.job.model.job import Job
81
82
from lp.services.propertycache import (
545
546
 
546
547
    def setSlaveForTesting(self, proxy):
547
548
        """See IBuilder."""
 
549
        # XXX JeroenVermeulen 2011-11-09, bug=888010: Don't use this.
 
550
        # It's a trap.  See bug for details.
548
551
        self._testing_slave = proxy
549
552
        del get_property_cache(self).slave
550
553
 
673
676
                bytes_written = out_file.tell()
674
677
                out_file.seek(0)
675
678
 
676
 
                library_file = getUtility(ILibraryFileAliasSet).create(
677
 
                    filename, bytes_written, out_file,
678
 
                    contentType=filenameToContentType(filename),
679
 
                    restricted=private)
 
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()
680
686
            finally:
681
687
                # Remove the temporary file.  getFile() closes the file
682
688
                # object.
714
720
    def acquireBuildCandidate(self):
715
721
        """Acquire a build candidate in an atomic fashion.
716
722
 
717
 
        When retrieiving a candidate we need to mark it as building
 
723
        When retrieving a candidate we need to mark it as building
718
724
        immediately so that it is not dispatched by another builder in the
719
725
        build manager.
720
726
 
724
730
        can be in this code at the same time.
725
731
 
726
732
        If there's ever more than one build manager running at once, then
727
 
        this code will need some sort of mutex.
 
733
        this code will need some sort of mutex, or run in a single
 
734
        transaction.
728
735
        """
729
736
        candidate = self._findBuildCandidate()
730
737
        if candidate is not None:
731
 
            candidate.markAsBuilding(self)
732
738
            transaction.commit()
 
739
            with DatabaseTransactionPolicy(read_only=False):
 
740
                candidate.markAsBuilding(self)
 
741
                transaction.commit()
733
742
        return candidate
734
743
 
735
744
    def _findBuildCandidate(self):