Skip to content

Commit

Permalink
Dynamically reduce dartdoc timeout with total time budget option.
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos committed Jan 25, 2024
1 parent 332fdfd commit 9b0b547
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
directory used for the analysis (helps switching different analyzer SDKs).
- `ToolEnvironment.create()` takes `pubHostedUrl` as `PackageAnalyzer.create()`
was removed.
- `InspectOptions.totalTimeBudget` to allow the dynamic reduction of `dartdocTimeout`.

**BREAKING CHANGES**

Expand Down
2 changes: 2 additions & 0 deletions lib/src/package_analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ import 'utils.dart';
class InspectOptions {
final String? pubHostedUrl;
final String? dartdocOutputDir;
final Duration? totalTimeBudget;
final Duration? dartdocTimeout;
final int? lineLength;

InspectOptions({
this.pubHostedUrl,
this.dartdocOutputDir,
this.totalTimeBudget,
this.dartdocTimeout,
this.lineLength,
});
Expand Down
14 changes: 12 additions & 2 deletions lib/src/package_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,23 @@ class PackageContext {
final String packageDir;
final errors = <String>[];
final urlProblems = <String, String>{};
final _stopwatch = Stopwatch();

Pubspec? _pubspec;
List<CodeProblem>? _codeProblems;

PackageContext({
required this.sharedContext,
required this.packageDir,
});
}) {
_stopwatch.start();
}

ToolEnvironment get toolEnvironment => sharedContext.toolEnvironment;
InspectOptions get options => sharedContext.options;
Duration? remainingTimeBudget() => options.totalTimeBudget == null
? null
: (options.totalTimeBudget! - _stopwatch.elapsed);

late final Version currentSdkVersion =
Version.parse(toolEnvironment.runtimeInfo.sdkVersion);
Expand Down Expand Up @@ -235,7 +241,11 @@ class PackageContext {
return DartdocResult.skipped();
}
if (await resolveDependencies()) {
final timeout = options.dartdocTimeout ?? const Duration(minutes: 5);
var timeout = options.dartdocTimeout ?? const Duration(minutes: 5);
final rtb = remainingTimeBudget();
if (rtb != null && rtb < timeout) {
timeout = rtb;
}
await normalizeDartdocOptionsYaml(packageDir);
try {
final pr = await toolEnvironment.dartdoc(
Expand Down

0 comments on commit 9b0b547

Please sign in to comment.