| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 datetime import datetime | 5 from datetime import datetime |
| 6 | 6 |
| 7 from common.http_client_appengine import HttpClientAppengine as HttpClient | 7 from common.http_client_appengine import HttpClientAppengine as HttpClient |
| 8 from model.wf_build import WfBuild | 8 from model.wf_build import WfBuild |
| 9 from waterfall import buildbot | 9 from waterfall import buildbot |
| 10 from waterfall import lock_util | 10 from waterfall import lock_util |
| 11 from waterfall import waterfall_config |
| 11 | 12 |
| 12 | 13 |
| 13 HTTP_CLIENT_LOGGING_ERRORS = HttpClient() | 14 HTTP_CLIENT_LOGGING_ERRORS = HttpClient() |
| 14 HTTP_CLIENT_NO_404_ERROR = HttpClient(no_error_logging_statuses=[404]) | 15 HTTP_CLIENT_NO_404_ERROR = HttpClient(no_error_logging_statuses=[404]) |
| 16 CHROME_BUILD_EXTRACT = 'CBE' |
| 17 BUILDBOT_MASTER = 'BM' |
| 15 | 18 |
| 16 | 19 |
| 17 def _BuildDataNeedUpdating(build): | 20 def _BuildDataNeedUpdating(build): |
| 18 return (not build.data or (not build.completed and | 21 return (not build.data or ( |
| 19 (datetime.utcnow() - build.last_crawled_time).total_seconds() >= 300)) | 22 not build.completed and ( |
| 23 datetime.utcnow() - build.last_crawled_time).total_seconds() >= 300)) |
| 20 | 24 |
| 21 | 25 |
| 22 def DownloadBuildData(master_name, builder_name, build_number): | 26 def DownloadBuildData(master_name, builder_name, build_number): |
| 23 """Downloads build data and returns a WfBuild instance.""" | 27 """Downloads build data and returns a WfBuild instance.""" |
| 24 build = WfBuild.Get(master_name, builder_name, build_number) | 28 build = WfBuild.Get(master_name, builder_name, build_number) |
| 25 if not build: | 29 if not build: |
| 26 build = WfBuild.Create(master_name, builder_name, build_number) | 30 build = WfBuild.Create(master_name, builder_name, build_number) |
| 27 | 31 |
| 28 # Cache the data to avoid pulling from master again. | 32 # Cache the data to avoid pulling from master again. |
| 29 if _BuildDataNeedUpdating(build): | 33 if _BuildDataNeedUpdating(build): |
| 30 # Retrieve build data from build archive first. | 34 use_cbe = waterfall_config.GetDownloadBuildDataSettings().get( |
| 31 build.data = buildbot.GetBuildDataFromArchive( | 35 'use_chrome_build_extract') |
| 32 master_name, builder_name, build_number, HTTP_CLIENT_NO_404_ERROR) | |
| 33 | 36 |
| 34 if build.data is None: | 37 if use_cbe: |
| 35 if not lock_util.WaitUntilDownloadAllowed( | 38 # Retrieve build data from build archive first. |
| 39 build.data = buildbot.GetBuildDataFromArchive( |
| 40 master_name, builder_name, build_number, HTTP_CLIENT_NO_404_ERROR) |
| 41 |
| 42 if build.data: |
| 43 build.data_source = CHROME_BUILD_EXTRACT |
| 44 elif not lock_util.WaitUntilDownloadAllowed( |
| 36 master_name): # pragma: no cover | 45 master_name): # pragma: no cover |
| 37 return None | 46 return None |
| 38 | 47 |
| 48 if not build.data: |
| 39 # Retrieve build data from build master. | 49 # Retrieve build data from build master. |
| 40 build.data = buildbot.GetBuildDataFromBuildMaster( | 50 build.data = buildbot.GetBuildDataFromBuildMaster( |
| 41 master_name, builder_name, build_number, HTTP_CLIENT_LOGGING_ERRORS) | 51 master_name, builder_name, build_number, HTTP_CLIENT_LOGGING_ERRORS) |
| 52 build.data_source = BUILDBOT_MASTER |
| 42 | 53 |
| 43 build.last_crawled_time = datetime.utcnow() | 54 build.last_crawled_time = datetime.utcnow() |
| 44 build.put() | 55 build.put() |
| 45 | 56 |
| 46 return build | 57 return build |
| OLD | NEW |