OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:io' hide HttpException; | 6 import 'dart:io' hide HttpException; |
7 | 7 |
8 import 'buildbot_data.dart'; | 8 import 'buildbot_data.dart'; |
9 import 'buildbot_loading.dart'; | 9 import 'buildbot_loading.dart'; |
10 import 'buildbot_structures.dart'; | 10 import 'buildbot_structures.dart'; |
11 import 'logdog.dart'; | 11 import 'logdog.dart'; |
12 import 'util.dart'; | 12 import 'util.dart'; |
13 | 13 |
14 /// Interface for pulling build bot results. | 14 /// Interface for pulling build bot results. |
15 abstract class BuildbotClient { | 15 abstract class BuildbotClient { |
16 /// Reads the [BuildResult] for the [buildUri]. | 16 /// Reads the [BuildResult] for the [buildUri]. |
17 Future<BuildResult> readResult(BuildUri buildUri); | 17 Future<BuildResult> readResult(BuildUri buildUri); |
18 | 18 |
19 int get mostRecentBuildNumber; | 19 int get mostRecentBuildNumber; |
20 | 20 |
21 /// Closes the client and cleans up its state. | 21 /// Closes the client and cleans up its state. |
22 void close(); | 22 void close(); |
23 } | 23 } |
24 | 24 |
25 /// Buildbot client that pulls build bot results through http. | 25 /// Buildbot client that pulls build bot results through http. |
26 class HttpBuildbotClient implements BuildbotClient { | 26 class HttpBuildbotClient implements BuildbotClient { |
27 final HttpClient _client = new HttpClient(); | 27 final HttpClient _client = new HttpClient(); |
28 | 28 |
| 29 static const int maxSkips = 3; |
| 30 |
29 @override | 31 @override |
30 Future<BuildResult> readResult(BuildUri buildUri) async { | 32 Future<BuildResult> readResult(BuildUri buildUri) async { |
| 33 int skips = 0; |
31 Duration timeout; | 34 Duration timeout; |
32 if (buildUri.buildNumber < 0) { | 35 if (buildUri.buildNumber < 0) { |
33 timeout = new Duration(seconds: 1); | 36 timeout = new Duration(seconds: 1); |
34 } | 37 } |
35 | 38 |
36 void skipToPreviousBuildNumber() { | 39 void skipToPreviousBuildNumber() { |
37 BuildUri prevBuildUri = buildUri.prev(); | 40 BuildUri prevBuildUri = buildUri.prev(); |
38 log('Skip build number on ${buildUri} -> ${prevBuildUri.buildNumber}'); | 41 log('Skip build number on ${buildUri} -> ${prevBuildUri.buildNumber}'); |
39 buildUri = buildUri.prev(); | 42 buildUri = buildUri.prev(); |
40 } | 43 } |
41 | 44 |
42 while (true) { | 45 while (true) { |
43 try { | 46 try { |
44 return await readBuildResultFromHttp(_client, buildUri, timeout); | 47 return await readBuildResultFromHttp(_client, buildUri, timeout); |
45 } on TimeoutException { | 48 } on TimeoutException { |
46 if (timeout != null) { | 49 if (timeout != null && skips < maxSkips) { |
| 50 skips++; |
47 skipToPreviousBuildNumber(); | 51 skipToPreviousBuildNumber(); |
48 continue; | 52 continue; |
49 } | 53 } |
50 return null; | 54 return null; |
51 } on HttpException { | 55 } on HttpException { |
52 if (timeout != null) { | 56 if (timeout != null && skips < maxSkips) { |
| 57 skips++; |
53 skipToPreviousBuildNumber(); | 58 skipToPreviousBuildNumber(); |
54 continue; | 59 continue; |
55 } | 60 } |
56 return null; | 61 return null; |
57 } on SocketException { | 62 } on SocketException { |
58 return null; | 63 return null; |
59 } | 64 } |
60 } | 65 } |
61 } | 66 } |
62 | 67 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 buildUri = buildUri.withBuildNumber(buildNumber); | 117 buildUri = buildUri.withBuildNumber(buildNumber); |
113 } | 118 } |
114 } | 119 } |
115 } | 120 } |
116 | 121 |
117 @override | 122 @override |
118 void close() { | 123 void close() { |
119 // Nothing to do. | 124 // Nothing to do. |
120 } | 125 } |
121 } | 126 } |
OLD | NEW |