Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: tools/gardening_tools/luci_api/lib/src/luci_services.dart

Issue 3005443002: Additional tools for gardening. (Closed)
Patch Set: Removed accidental commit Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 import 'dart:async';
2 import 'dart:math';
3 import 'package:base_lib/base_lib.dart';
4
5 import 'luci_api.dart';
6
7 /// Fetches the latest builds for a bot and caches the results.
8 Future<Try<List<BuildDetail>>> fetchAndCacheLatestBuilds(
9 LuciApi api,
10 Logger logger,
11 String client,
12 String botName,
13 PerformWithCache cache,
14 int amount) async {
15 logger.debug("Finding latest build for bot $botName...");
16 var result = await api.getBuildBotDetails(
17 client, botName, cache(duration: new Duration(minutes: 15)));
18 return result
19 .bindAsync<List<BuildDetail>>((LuciBuildBotDetail botDetail) async {
20 int buildNo = botDetail.latestBuildNumber();
21 int lo = max(0, buildNo - amount);
22 List<Future<Try<BuildDetail>>> builds =
23 new List<Future<Try<BuildDetail>>>();
24 logger.debug("Finding builds #${lo}-#${buildNo} for bot $botName...");
25 for (buildNo; buildNo > lo; buildNo--) {
26 builds.add(api.getBuildDetails(
27 client, botName, buildNo, cache(duration: new Duration(days: 1))));
28 }
29 List<Try<BuildDetail>> buildsCompleted = await Future.wait(builds);
30 logger.debug("Finished finding builds for bot $botName");
31 return buildsCompleted
32 .where((bd) => !bd.isError())
33 .map((bd) => bd.get())
34 .toList();
35 });
36 }
37
38 /// Fetches all builds for a given [commit]-hash, by searching the latest [amoun t] builds.
39 Future<Try<List<BuildDetail>>> fetchBuildsForCommmit(LuciApi api, Logger logger,
40 String client, String commit, PerformWithCache cache,
41 [int amount = 20]) async {
42 logger.info(
43 """Sorry - this is going to take some time, since we have to look into all $amount latest builds for all bots for client $client.
44 Subsequent queries run faster if caching is turned on...""");
45
46 logger.debug("Finding all bots for client $client");
47 var buildBots = await api.getPrimaryBuilders(
48 client, cache(duration: new Duration(minutes: 30)));
49 return (await buildBots.bindAsync((List<LuciBuildBot> buildBots) async {
50 var buildBotBuilds = <Try<List<BuildDetail>>>[];
51 for (var buildBot in buildBots) {
52 buildBotBuilds.add(await fetchAndCacheLatestBuilds(
53 api, logger, client, buildBot.name, cache, amount));
54 }
55 logger.debug(
56 "All latest $amount builds found for client $client. Processing results. ..");
57 return buildBotBuilds
58 .map((tryBotBuild) {
59 if (tryBotBuild.isError()) {
60 logger.warning("Problem getting results", tryBotBuild.getError(),
61 tryBotBuild.getStackTrace());
62 }
63 return tryBotBuild.getOrDefault(new List<BuildDetail>());
64 })
65 .expand((id) => id)
66 .toList();
67 })).bind((List<BuildDetail> buildDetails) {
68 return buildDetails.where((BuildDetail buildDetail) {
69 return buildDetail.allChanges.any((change) => change.revision == commit);
70 });
71 });
72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698