| 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 common.http_client_appengine import HttpClientAppengine as HttpClient | 5 from common.http_client_appengine import HttpClientAppengine as HttpClient |
| 6 from libs import time_util | 6 from libs import time_util |
| 7 from model.wf_build import WfBuild | 7 from model.wf_build import WfBuild |
| 8 from waterfall import buildbot | 8 from waterfall import buildbot |
| 9 from waterfall import lock_util | 9 from waterfall import lock_util |
| 10 from waterfall import waterfall_config | 10 from waterfall import waterfall_config |
| 11 | 11 |
| 12 | 12 |
| 13 HTTP_CLIENT_LOGGING_ERRORS = HttpClient() | 13 HTTP_CLIENT_LOGGING_ERRORS = HttpClient() |
| 14 HTTP_CLIENT_NO_404_ERROR = HttpClient(no_error_logging_statuses=[404]) | 14 HTTP_CLIENT_NO_404_ERROR = HttpClient(no_error_logging_statuses=[404]) |
| 15 CHROME_BUILD_EXTRACT = 'CBE' | 15 CHROME_BUILD_EXTRACT = 'CBE' |
| 16 BUILDBOT_MASTER = 'BM' | 16 BUILDBOT_MASTER = 'BM' |
| 17 | 17 |
| 18 | 18 |
| 19 def _BuildDataNeedUpdating(build): | 19 def _BuildDataNeedUpdating(build): |
| 20 return (not build.data or ( | 20 return (not build.data or ( |
| 21 not build.completed and ( | 21 not build.completed and ( |
| 22 time_util.GetUTCNow() - build.last_crawled_time | 22 time_util.GetUTCNow() - build.last_crawled_time |
| 23 ).total_seconds() >= 300)) | 23 ).total_seconds() >= 300)) |
| 24 | 24 |
| 25 | 25 |
| 26 def DownloadBuildData(master_name, builder_name, build_number): | 26 def DownloadBuildData(master_name, builder_name, build_number): |
| 27 """Downloads build data and returns a WfBuild instance.""" | 27 """Downloads build data and returns a WfBuild instance.""" |
| 28 build = WfBuild.Get(master_name, builder_name, build_number) | 28 build = WfBuild.Get(master_name, builder_name, build_number) |
| 29 if not build: | 29 if not build: |
| 30 build = WfBuild.Create(master_name, builder_name, build_number) | 30 build = WfBuild.Create(master_name, builder_name, build_number) |
| 31 | 31 |
| 32 # Cache the data to avoid pulling from master again. | 32 # Cache the data to avoid pulling from master again. |
| 33 if _BuildDataNeedUpdating(build): | 33 if _BuildDataNeedUpdating(build): |
| (...skipping 16 matching lines...) Expand all Loading... |
| 50 build.data = buildbot.GetBuildDataFromBuildMaster( | 50 build.data = buildbot.GetBuildDataFromBuildMaster( |
| 51 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 | 52 build.data_source = BUILDBOT_MASTER |
| 53 | 53 |
| 54 build.last_crawled_time = time_util.GetUTCNow() | 54 build.last_crawled_time = time_util.GetUTCNow() |
| 55 build.put() | 55 build.put() |
| 56 | 56 |
| 57 return build | 57 return build |
| 58 | 58 |
| 59 | 59 |
| 60 def GetBuildInfo(master_name, builder_name, build_number): |
| 61 """Gets build info given a master, builder, and build number. |
| 62 |
| 63 Args: |
| 64 master_name (str): The name of the master. |
| 65 builder_name (str): The name of the builder. |
| 66 build_number (int): The build number. |
| 67 |
| 68 Returns: |
| 69 Build information as an instance of BuildInfo. |
| 70 """ |
| 71 build = DownloadBuildData(master_name, builder_name, build_number) |
| 72 |
| 73 if not build.data: |
| 74 return None |
| 75 |
| 76 return buildbot.ExtractBuildInfo( |
| 77 master_name, builder_name, build_number, build.data) |
| 78 |
| 79 |
| 60 def GetBuildEndTime(master_name, builder_name, build_number): | 80 def GetBuildEndTime(master_name, builder_name, build_number): |
| 61 build = DownloadBuildData(master_name, builder_name, build_number) | 81 build = DownloadBuildData(master_name, builder_name, build_number) |
| 62 build_info = buildbot.ExtractBuildInfo( | 82 build_info = buildbot.ExtractBuildInfo( |
| 63 master_name, builder_name, build_number, build.data) | 83 master_name, builder_name, build_number, build.data) |
| 64 return build_info.build_end_time | 84 return build_info.build_end_time |
| 65 | 85 |
| 66 | 86 |
| 67 def CreateBuildId(master_name, builder_name, build_number): | 87 def CreateBuildId(master_name, builder_name, build_number): |
| 68 return '%s/%s/%s' % (master_name, builder_name, build_number) | 88 return '%s/%s/%s' % (master_name, builder_name, build_number) |
| 69 | 89 |
| 70 | 90 |
| 71 def GetBuildInfoFromId(build_id): | 91 def GetBuildInfoFromId(build_id): |
| 72 return build_id.split('/') | 92 return build_id.split('/') |
| OLD | NEW |