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(state, last_build): | |
|
ojan
2014/08/14 22:47:19
Look at alert_builder_tests.test_find_current_step
| |
| 182 last_update = float(0) | |
| 183 if state == 'offline': | |
|
ojan
2014/08/14 22:47:19
We should get the same time whether the bot is off
| |
| 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 |
|
ojan
2014/08/14 22:47:19
If you'd be willing to write tests for this while
| |
| 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']) |
| 200 state = builder_json['state'] | |
| 190 last_finished_id = sorted(recent_builds - active_builds, reverse=True)[0] | 201 last_finished_id = sorted(recent_builds - active_builds, reverse=True)[0] |
| 202 #last update from here -- if offline last finish time, | |
| 203 # otherwise iterate across steps to find the start time of the running one | |
|
ojan
2014/08/14 22:47:19
Leftover comment?
| |
| 191 last_build = fetch_build_json(cache, | 204 last_build = fetch_build_json(cache, |
| 192 master_url, builder_name, last_finished_id) | 205 master_url, builder_name, last_finished_id) |
| 193 latest_revisions[master_name][builder_name] = \ | 206 latest_builder_info[master_name][builder_name] = collections.defaultdict(dic t) |
|
ojan
2014/08/14 22:47:19
No need to defaultdict here.
latest_builder_info[
| |
| 207 latest_builder_info[master_name][builder_name]['revisions'] = \ | |
|
ojan
2014/08/14 22:47:19
The old code had the wrong style. multi-lines shou
| |
| 194 revisions_from_build(last_build) | 208 revisions_from_build(last_build) |
| 195 return latest_revisions | 209 latest_builder_info[master_name][builder_name]['state'] = state |
| 210 latest_builder_info[master_name][builder_name]['lastUpdateTime'] = \ | |
| 211 latest_update_time_for_builder(state, last_build) | |
| 212 return latest_builder_info | |
| 196 | 213 |
| 197 | 214 |
| 198 def warm_build_cache(cache, master_url, builder_name, | 215 def warm_build_cache(cache, master_url, builder_name, |
| 199 recent_build_ids, active_builds): # pragma: no cover | 216 recent_build_ids, active_builds): # pragma: no cover |
| 200 # Cache active (in-progress) builds: | 217 # Cache active (in-progress) builds: |
| 201 match_builder_name = lambda build: build['builderName'] == builder_name | 218 match_builder_name = lambda build: build['builderName'] == builder_name |
| 202 actives = filter(match_builder_name, active_builds) | 219 actives = filter(match_builder_name, active_builds) |
| 203 for build in actives: | 220 for build in actives: |
| 204 key = cache_key_for_build(master_url, builder_name, build['number']) | 221 key = cache_key_for_build(master_url, builder_name, build['number']) |
| 205 cache.set(key, build) | 222 cache.set(key, build) |
| 206 | 223 |
| 207 active_build_ids = [b['number'] for b in active_builds] | 224 active_build_ids = [b['number'] for b in active_builds] |
| 208 # recent_build_ids includes active ones. | 225 # recent_build_ids includes active ones. |
| 209 finished_build_ids = [b for b in recent_build_ids | 226 finished_build_ids = [b for b in recent_build_ids |
| 210 if b not in active_build_ids] | 227 if b not in active_build_ids] |
| 211 last_build_id = max(finished_build_ids) | 228 last_build_id = max(finished_build_ids) |
| 212 cache_key = cache_key_for_build(master_url, builder_name, last_build_id) | 229 cache_key = cache_key_for_build(master_url, builder_name, last_build_id) |
| 213 | 230 |
| 214 # We cache in-progress builds, so if the first finished build has a non-None | 231 # 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. | 232 # eta, then it's just the cached version from when it was in progress. |
| 216 cached_build = cache.get(cache_key) | 233 cached_build = cache.get(cache_key) |
| 217 if not cached_build or cached_build.get('eta') is not None: | 234 if not cached_build or cached_build.get('eta') is not None: |
| 218 # reason = 'in progress' if cached_build else 'missing' | 235 # reason = 'in progress' if cached_build else 'missing' |
| 219 # logging.debug('prefill reason: %s %s' % (max(finished_build_ids), reason)) | 236 # logging.debug('prefill reason: %s %s' % (max(finished_build_ids), reason)) |
| 220 prefill_builds_cache(cache, master_url, builder_name) | 237 prefill_builds_cache(cache, master_url, builder_name) |
| OLD | NEW |