Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import collections | 5 import collections |
| 6 import datetime | 6 import datetime |
| 7 import json | 7 import json |
| 8 import logging | 8 import logging |
| 9 import operator | 9 import operator |
| 10 import os | 10 import os |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 # parent_got_foo_revision instead, but non-tester builders | 171 # parent_got_foo_revision instead, but non-tester builders |
| 172 # don't have the parent_ versions, so we have to fall back | 172 # don't have the parent_ versions, so we have to fall back |
| 173 # to got_foo_revision in those cases! | 173 # to got_foo_revision in those cases! |
| 174 # Don't even think about using 'revision' that's wrong too. | 174 # Don't even think about using 'revision' that's wrong too. |
| 175 revision = _property_value(build_json, 'parent_' + buildbot_property) | 175 revision = _property_value(build_json, 'parent_' + buildbot_property) |
| 176 if not revision: | 176 if not revision: |
| 177 revision = _property_value(build_json, buildbot_property) | 177 revision = _property_value(build_json, buildbot_property) |
| 178 revisions[repo_name] = revision | 178 revisions[repo_name] = revision |
| 179 return revisions | 179 return revisions |
| 180 | 180 |
| 181 def latest_update_time_for_builder(last_build): | |
| 182 last_update = float(0) | |
|
eseidel
2014/08/18 16:35:43
None?
leviw_travelin_and_unemployed
2014/08/18 18:39:02
Sure!
| |
| 183 if last_build['times'][1] != None: | |
| 184 last_update = float(last_build['times'][1]) | |
| 185 else: | |
| 186 for step in last_build['steps']: | |
| 187 step_time = float(step['times'][0]) | |
| 188 last_update = max(step_time, last_update) | |
| 189 return last_update | |
| 190 | |
| 181 | 191 |
| 182 # "line too long" pylint: disable=C0301 | 192 # "line too long" pylint: disable=C0301 |
| 183 def latest_revisions_for_master(cache, master_url, master_json): # pragma: no c over | 193 def latest_builder_info_for_master(cache, master_url, master_json): # pragma: n o cover |
| 184 latest_revisions = collections.defaultdict(dict) | 194 latest_builder_info = collections.defaultdict(dict) |
| 185 master_name = master_name_from_url(master_url) | 195 master_name = master_name_from_url(master_url) |
| 186 for builder_name, builder_json in master_json['builders'].items(): | 196 for builder_name, builder_json in master_json['builders'].items(): |
| 187 # recent_builds can include current builds | 197 # recent_builds can include current builds |
| 188 recent_builds = set(builder_json['cachedBuilds']) | 198 recent_builds = set(builder_json['cachedBuilds']) |
| 189 active_builds = set(builder_json['currentBuilds']) | 199 active_builds = set(builder_json['currentBuilds']) |
| 190 last_finished_id = sorted(recent_builds - active_builds, reverse=True)[0] | 200 last_finished_id = sorted(recent_builds - active_builds, reverse=True)[0] |
| 191 last_build = fetch_build_json(cache, | 201 last_build = fetch_build_json(cache, |
| 192 master_url, builder_name, last_finished_id) | 202 master_url, builder_name, last_finished_id) |
| 193 latest_revisions[master_name][builder_name] = \ | 203 latest_builder_info[master_name][builder_name] = { |
| 194 revisions_from_build(last_build) | 204 'revisions': revisions_from_build(last_build), |
| 195 return latest_revisions | 205 'state': builder_json['state'], |
| 206 'lastUpdateTime': latest_update_time_for_builder(last_build), | |
|
eseidel
2014/08/18 16:35:43
What does 0 mean here?
leviw_travelin_and_unemployed
2014/08/18 18:39:02
It should never actually be zero. It should be Non
| |
| 207 } | |
| 208 return latest_builder_info | |
| 196 | 209 |
| 197 | 210 |
| 198 def warm_build_cache(cache, master_url, builder_name, | 211 def warm_build_cache(cache, master_url, builder_name, |
| 199 recent_build_ids, active_builds): # pragma: no cover | 212 recent_build_ids, active_builds): # pragma: no cover |
| 200 # Cache active (in-progress) builds: | 213 # Cache active (in-progress) builds: |
| 201 match_builder_name = lambda build: build['builderName'] == builder_name | 214 match_builder_name = lambda build: build['builderName'] == builder_name |
| 202 actives = filter(match_builder_name, active_builds) | 215 actives = filter(match_builder_name, active_builds) |
| 203 for build in actives: | 216 for build in actives: |
| 204 key = cache_key_for_build(master_url, builder_name, build['number']) | 217 key = cache_key_for_build(master_url, builder_name, build['number']) |
| 205 cache.set(key, build) | 218 cache.set(key, build) |
| 206 | 219 |
| 207 active_build_ids = [b['number'] for b in active_builds] | 220 active_build_ids = [b['number'] for b in active_builds] |
| 208 # recent_build_ids includes active ones. | 221 # recent_build_ids includes active ones. |
| 209 finished_build_ids = [b for b in recent_build_ids | 222 finished_build_ids = [b for b in recent_build_ids |
| 210 if b not in active_build_ids] | 223 if b not in active_build_ids] |
| 211 last_build_id = max(finished_build_ids) | 224 last_build_id = max(finished_build_ids) |
| 212 cache_key = cache_key_for_build(master_url, builder_name, last_build_id) | 225 cache_key = cache_key_for_build(master_url, builder_name, last_build_id) |
| 213 | 226 |
| 214 # We cache in-progress builds, so if the first finished build has a non-None | 227 # We cache in-progress builds, so if the first finished build has a non-None |
| 215 # eta, then it's just the cached version from when it was in progress. | 228 # eta, then it's just the cached version from when it was in progress. |
| 216 cached_build = cache.get(cache_key) | 229 cached_build = cache.get(cache_key) |
| 217 if not cached_build or cached_build.get('eta') is not None: | 230 if not cached_build or cached_build.get('eta') is not None: |
| 218 # reason = 'in progress' if cached_build else 'missing' | 231 # reason = 'in progress' if cached_build else 'missing' |
| 219 # logging.debug('prefill reason: %s %s' % (max(finished_build_ids), reason)) | 232 # logging.debug('prefill reason: %s %s' % (max(finished_build_ids), reason)) |
| 220 prefill_builds_cache(cache, master_url, builder_name) | 233 prefill_builds_cache(cache, master_url, builder_name) |
| OLD | NEW |