Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5e808aa

Browse files
committed
[infra] Add retry logic to find_base_commit.
The buildbucket API is not always reliable and responds within 30 seconds. Rather than spuriously failing, try again. This should improve the reliability of the base branch update bot. Change-Id: Iade2d78372743b8d843c0dead591c28f8ee8f3ae Reviewed-on: https://dart-review.googlesource.com/c/88445 Reviewed-by: William Hesse <[email protected]>
1 parent e8c60f7 commit 5e808aa

1 file changed

Lines changed: 26 additions & 9 deletions

File tree

tools/bots/find_base_commit.dart

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
// Find the newest commit that has a full set of results on the bots.
77

8+
import 'dart:async';
89
import 'dart:convert';
910
import 'dart:io';
1011
import 'dart:math';
@@ -50,15 +51,31 @@ ${parser.usage}""");
5051
"&max_builds=$maxBuilds"
5152
"&status=COMPLETED"
5253
"&fields=builds(url%2Cparameters_json)");
53-
final client = new HttpClient();
54-
final request = await client.getUrl(url).timeout(const Duration(seconds: 30));
55-
final response = await request.close().timeout(const Duration(seconds: 30));
56-
final Map<String, dynamic> object = await response
57-
.transform(new Utf8Decoder())
58-
.transform(new JsonDecoder())
59-
.first
60-
.timeout(const Duration(seconds: 30));
61-
client.close();
54+
const maxRetries = 3;
55+
const timeout = const Duration(seconds: 30);
56+
Map<String, dynamic> object;
57+
for (int i = 1; i <= maxRetries; i++) {
58+
try {
59+
final client = new HttpClient();
60+
final request = await client.getUrl(url).timeout(timeout);
61+
final response = await request.close().timeout(timeout);
62+
object = await response
63+
.transform(new Utf8Decoder())
64+
.transform(new JsonDecoder())
65+
.first
66+
.timeout(timeout);
67+
client.close();
68+
break;
69+
} on TimeoutException catch (e) {
70+
final inSeconds = e.duration.inSeconds;
71+
stderr.writeln(
72+
"Attempt $i of $maxRetries timed out after $inSeconds seconds");
73+
if (i == maxRetries) {
74+
stderr.writeln("error: Failed to download $url");
75+
exit(1);
76+
}
77+
}
78+
}
6279

6380
// Locate the builds we're interested in and map them to each commit. The
6481
// builds returned by the API are sorted with the newest first. Since bots

0 commit comments

Comments
 (0)