OLD | NEW |
---|---|
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 from dashboard.pinpoint.models import isolate | 5 from dashboard.pinpoint.models import isolate |
6 from dashboard.pinpoint.models.quest import execution | 6 from dashboard.pinpoint.models.quest import execution |
7 from dashboard.pinpoint.models.quest import quest | 7 from dashboard.pinpoint.models.quest import quest |
8 from dashboard.services import buildbucket_service | 8 from dashboard.services import buildbucket_service |
9 | 9 |
10 | 10 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 self._target = target | 42 self._target = target |
43 self._change = change | 43 self._change = change |
44 self._build = None | 44 self._build = None |
45 | 45 |
46 def _AsDict(self): | 46 def _AsDict(self): |
47 return { | 47 return { |
48 'build': self._build, | 48 'build': self._build, |
49 } | 49 } |
50 | 50 |
51 def _Poll(self): | 51 def _Poll(self): |
52 # Look for the .isolate in our cache. | 52 if self._CheckIsolateCache(): |
53 return | |
54 | |
55 if self._build: | |
56 self._CheckBuildStatus() | |
57 return | |
58 | |
59 self._RequestBuild() | |
60 | |
61 def _CheckIsolateCache(self): | |
62 """Checks the isolate cache to see if a build is already available. | |
63 | |
64 Returns: | |
65 True iff the isolate was found and the execution is completed. | |
perezju
2017/09/13 13:46:38
nit: Maybe this should be called "_CheckCompleted"
dtu
2017/09/13 15:16:05
Done.
| |
66 """ | |
53 try: | 67 try: |
54 isolate_hash = isolate.Get(self._builder_name, self._change, self._target) | 68 isolate_hash = isolate.Get(self._builder_name, self._change, self._target) |
55 except KeyError: | 69 except KeyError: |
56 isolate_hash = None | 70 return False |
71 self._Complete(result_arguments={'isolate_hash': isolate_hash}) | |
72 return True | |
57 | 73 |
58 if isolate_hash: | 74 def _CheckBuildStatus(self): |
59 self._Complete( | 75 """Checks on the status of a previously requested build. |
60 result_arguments={'isolate_hash': isolate_hash}) | 76 |
77 Raises: | |
78 BuildError: The build failed, was canceled, or didn't produce an isolate. | |
79 """ | |
80 status = buildbucket_service.GetJobStatus(self._build) | |
81 | |
82 if status['build']['status'] != 'COMPLETED': | |
61 return | 83 return |
62 | 84 |
63 # Check the status of a previously requested build. | 85 if status['build']['result'] == 'FAILURE': |
64 if self._build: | 86 raise BuildError('Build failed: ' + status['build']['failure_reason']) |
65 status = buildbucket_service.GetJobStatus(self._build) | 87 elif status['build']['result'] == 'CANCELED': |
88 raise BuildError('Build was canceled: ' + | |
89 status['build']['cancelation_reason']) | |
90 else: | |
91 if self._CheckIsolateCache(): | |
92 return | |
93 raise BuildError('Buildbucket says the build completed successfully, ' | |
94 "but Pinpoint can't find the isolate hash.") | |
66 | 95 |
67 if status['build']['status'] != 'COMPLETED': | 96 def _RequestBuild(self): |
68 return | 97 """Requests a build. |
69 | 98 |
70 if status['build']['result'] == 'FAILURE': | 99 If a previous Execution already requested a build for this Change, returns |
71 raise BuildError('Build failed: ' + status['build']['failure_reason']) | 100 that build instead of requesting a new one. |
72 elif status['build']['result'] == 'CANCELED': | 101 """ |
73 raise BuildError('Build was canceled: ' + | |
74 status['build']['cancelation_reason']) | |
75 else: | |
76 # It's possible for there to be a race condition if the builder uploads | |
77 # the isolate and completes the build between the above isolate lookup | |
78 # and buildbucket lookup, but right now, it takes builds a few minutes | |
79 # to package the build, so that doesn't happen. | |
80 raise BuildError('Buildbucket says the build completed successfully, ' | |
81 "but Pinpoint can't find the isolate hash.") | |
82 | |
83 if self._change in self._previous_builds: | 102 if self._change in self._previous_builds: |
84 # If another Execution already requested a build, reuse that one. | 103 # If another Execution already requested a build, reuse that one. |
85 self._build = self._previous_builds[self._change] | 104 self._build = self._previous_builds[self._change] |
86 else: | 105 else: |
87 # Request a build! | 106 # Request a build! |
88 buildbucket_info = _RequestBuild(self._builder_name, self._change) | 107 buildbucket_info = _RequestBuild(self._builder_name, self._change) |
89 self._build = buildbucket_info['build']['id'] | 108 self._build = buildbucket_info['build']['id'] |
90 self._previous_builds[self._change] = self._build | 109 self._previous_builds[self._change] = self._build |
91 | 110 |
92 | 111 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 # https://github.com/catapult-project/catapult/issues/3599 | 155 # https://github.com/catapult-project/catapult/issues/3599 |
137 parameters['properties'].update({ | 156 parameters['properties'].update({ |
138 'patch_storage': 'rietveld', | 157 'patch_storage': 'rietveld', |
139 'rietveld': change.patch.server, | 158 'rietveld': change.patch.server, |
140 'issue': change.patch.issue, | 159 'issue': change.patch.issue, |
141 'patchset': change.patch.patchset, | 160 'patchset': change.patch.patchset, |
142 }) | 161 }) |
143 | 162 |
144 # TODO: Look up Buildbucket bucket from builder_name. | 163 # TODO: Look up Buildbucket bucket from builder_name. |
145 return buildbucket_service.Put(BUCKET, parameters) | 164 return buildbucket_service.Put(BUCKET, parameters) |
OLD | NEW |