Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # This file is part of Buildbot. Buildbot is free software: you can | 1 # This file is part of Buildbot. Buildbot is free software: you can |
| 2 # redistribute it and/or modify it under the terms of the GNU General Public | 2 # redistribute it and/or modify it under the terms of the GNU General Public |
| 3 # License as published by the Free Software Foundation, version 2. | 3 # License as published by the Free Software Foundation, version 2. |
| 4 # | 4 # |
| 5 # This program is distributed in the hope that it will be useful, but WITHOUT | 5 # This program is distributed in the hope that it will be useful, but WITHOUT |
| 6 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 6 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 7 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | 7 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 8 # details. | 8 # details. |
| 9 # | 9 # |
| 10 # You should have received a copy of the GNU General Public License along with | 10 # You should have received a copy of the GNU General Public License along with |
| 11 # this program; if not, write to the Free Software Foundation, Inc., 51 | 11 # this program; if not, write to the Free Software Foundation, Inc., 51 |
| 12 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 12 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 13 # | 13 # |
| 14 # Copyright Buildbot Team Members | 14 # Copyright Buildbot Team Members |
| 15 | 15 |
| 16 | 16 |
| 17 import random, weakref | 17 import inspect, random, weakref |
| 18 from zope.interface import implements | 18 from zope.interface import implements |
| 19 from twisted.python import log, failure | 19 from twisted.python import log, failure |
| 20 from twisted.spread import pb | 20 from twisted.spread import pb |
| 21 from twisted.application import service, internet | 21 from twisted.application import service, internet |
| 22 from twisted.internet import defer | 22 from twisted.internet import defer |
| 23 | 23 |
| 24 from buildbot import interfaces | 24 from buildbot import interfaces |
| 25 from buildbot.status.progress import Expectations | 25 from buildbot.status.progress import Expectations |
| 26 from buildbot.status.builder import RETRY | 26 from buildbot.status.builder import RETRY |
| 27 from buildbot.status.buildrequest import BuildRequestStatus | 27 from buildbot.status.buildrequest import BuildRequestStatus |
| (...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 846 # we'll need BuildRequest objects, so get those first | 846 # we'll need BuildRequest objects, so get those first |
| 847 wfd = defer.waitForDeferred( | 847 wfd = defer.waitForDeferred( |
| 848 defer.gatherResults( | 848 defer.gatherResults( |
| 849 [ self._brdictToBuildRequest(brdict) | 849 [ self._brdictToBuildRequest(brdict) |
| 850 for brdict in unclaimed_requests ])) | 850 for brdict in unclaimed_requests ])) |
| 851 yield wfd | 851 yield wfd |
| 852 unclaimed_request_objects = wfd.getResult() | 852 unclaimed_request_objects = wfd.getResult() |
| 853 breq_object = unclaimed_request_objects.pop( | 853 breq_object = unclaimed_request_objects.pop( |
| 854 unclaimed_requests.index(breq)) | 854 unclaimed_requests.index(breq)) |
| 855 | 855 |
| 856 # Make sure the merge-requests function can take the queue length. | |
| 857 mergeRequests_with_length_fn = lambda a, b, _ : mergeRequests_fn(a, b) | |
| 858 try: | |
| 859 if len(inspect.getargspec(mergeRequests_fn).args) > 2: | |
| 860 mergeRequests_with_length_fn = mergeRequests_fn | |
| 861 except Exception: | |
| 862 pass | |
| 863 | |
| 864 # This might not reflect exact number of items that could be merged | |
| 865 # (this depends on the canBeMergedWith algorithm), but it can help | |
| 866 # indicating how loaded this builder is. | |
| 867 queue_length = len(unclaimed_request_objects) | |
| 868 | |
| 856 # gather the mergeable requests | 869 # gather the mergeable requests |
| 857 merged_request_objects = [breq_object] | 870 merged_request_objects = [breq_object] |
| 858 for other_breq_object in unclaimed_request_objects: | 871 for other_breq_object in unclaimed_request_objects: |
| 859 wfd = defer.waitForDeferred( | 872 wfd = defer.waitForDeferred( |
| 860 defer.maybeDeferred(lambda : | 873 defer.maybeDeferred(lambda : |
| 861 mergeRequests_fn(breq_object, other_breq_object))) | 874 mergeRequests_with_length_fn( |
| 875 breq_object, other_breq_object, queue_length))) | |
| 862 yield wfd | 876 yield wfd |
| 863 if wfd.getResult(): | 877 if wfd.getResult(): |
| 864 merged_request_objects.append(other_breq_object) | 878 merged_request_objects.append(other_breq_object) |
|
Michael Achenbach
2016/10/13 10:36:13
Thinking more: Now that I'm already changing this
| |
| 865 | 879 |
| 866 # convert them back to brdicts and return | 880 # convert them back to brdicts and return |
| 867 merged_requests = [ br.brdict for br in merged_request_objects ] | 881 merged_requests = [ br.brdict for br in merged_request_objects ] |
| 868 yield merged_requests | 882 yield merged_requests |
| 869 | 883 |
| 870 def _brdictToBuildRequest(self, brdict): | 884 def _brdictToBuildRequest(self, brdict): |
| 871 """ | 885 """ |
| 872 Convert a build request dictionary to a L{buildrequest.BuildRequest} | 886 Convert a build request dictionary to a L{buildrequest.BuildRequest} |
| 873 object, caching the result in the dictionary itself. The resulting | 887 object, caching the result in the dictionary itself. The resulting |
| 874 buildrequest will have a C{brdict} attribute pointing back to this | 888 buildrequest will have a C{brdict} attribute pointing back to this |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 979 d = defer.DeferredList(dl) | 993 d = defer.DeferredList(dl) |
| 980 d.addCallback(self._gatherPingResults) | 994 d.addCallback(self._gatherPingResults) |
| 981 return d | 995 return d |
| 982 | 996 |
| 983 def _gatherPingResults(self, res): | 997 def _gatherPingResults(self, res): |
| 984 for ignored,success in res: | 998 for ignored,success in res: |
| 985 if not success: | 999 if not success: |
| 986 return False | 1000 return False |
| 987 return True | 1001 return True |
| 988 | 1002 |
| OLD | NEW |