Make "pub get" retry once a second when it fails. (#11882)

This commit is contained in:
Ian Hickson
2017-08-31 19:35:05 -07:00
committed by GitHub
parent 42bd30dd3f
commit 2cbc4a0202
4 changed files with 204 additions and 11 deletions

View File

@@ -103,7 +103,7 @@ class PackagesTestCommand extends FlutterCommand {
}
@override
Future<Null> runCommand() => pub(<String>['run', 'test']..addAll(argResults.rest));
Future<Null> runCommand() => pub(<String>['run', 'test']..addAll(argResults.rest), retry: false);
}
class PackagesPassthroughCommand extends FlutterCommand {
@@ -124,5 +124,5 @@ class PackagesPassthroughCommand extends FlutterCommand {
}
@override
Future<Null> runCommand() => pub(argResults.rest);
Future<Null> runCommand() => pub(argResults.rest, retry: false);
}

View File

@@ -4,6 +4,8 @@
import 'dart:async';
import 'package:meta/meta.dart';
import '../base/common.dart';
import '../base/file_system.dart';
import '../base/logger.dart';
@@ -55,7 +57,13 @@ Future<Null> pubGet({
if (offline)
args.add('--offline');
try {
await pub(args, directory: directory, filter: _filterOverrideWarnings, failureMessage: 'pub $command failed');
await pub(
args,
directory: directory,
filter: _filterOverrideWarnings,
failureMessage: 'pub $command failed',
retry: true,
);
} finally {
status.stop();
}
@@ -73,15 +81,29 @@ typedef String MessageFilter(String message);
Future<Null> pub(List<String> arguments, {
String directory,
MessageFilter filter,
String failureMessage: 'pub failed'
String failureMessage: 'pub failed',
@required bool retry,
}) async {
final List<String> command = <String>[ sdkBinaryName('pub') ]..addAll(arguments);
final int code = await runCommandAndStreamOutput(
command,
workingDirectory: directory,
mapFunction: filter,
environment: <String, String>{ 'FLUTTER_ROOT': Cache.flutterRoot, _pubEnvironmentKey: _getPubEnvironmentValue() }
);
int attempts = 0;
int duration = 1;
int code;
while (true) {
attempts += 1;
code = await runCommandAndStreamOutput(
command,
workingDirectory: directory,
mapFunction: filter,
environment: <String, String>{ 'FLUTTER_ROOT': Cache.flutterRoot, _pubEnvironmentKey: _getPubEnvironmentValue() }
);
if (code != 69) // UNAVAILABLE in https://github.com/dart-lang/pub/blob/master/lib/src/exit_codes.dart
break;
printStatus('$failureMessage ($code) -- attempting retry $attempts in $duration second${ duration == 1 ? "" : "s"}...');
await new Future<Null>.delayed(new Duration(seconds: duration));
if (duration < 64)
duration *= 2;
}
assert(code != null);
if (code != 0)
throwToolExit('$failureMessage ($code)', exitCode: code);
}