Skip to content

Commit

Permalink
Add retries to pub.dev/api/ calls (#199)
Browse files Browse the repository at this point in the history
* Add retries to pub client calls

* Remove type

* Add changelog entry

* Also post workflow failures
  • Loading branch information
mosuem authored Nov 22, 2023
1 parent 4cc2cb4 commit 805ab4f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/post_summaries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ jobs:
pull-requests: write
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
github.event.workflow_run.event == 'pull_request'
continue-on-error: true
steps:

Expand Down
4 changes: 4 additions & 0 deletions pkgs/firehose/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.33

- Retry calls to pub.dev API.

## 0.3.32

- Fix an issue validating pre-release git publishing tags (#176).
Expand Down
18 changes: 16 additions & 2 deletions pkgs/firehose/lib/src/pub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Pub {
http.Client get httpClient => _httpClient ??= http.Client();

Future<bool> hasPublishedVersion(String name, String version) async {
var response =
await httpClient.get(Uri.parse('https://pub.dev/api/packages/$name'));
var uri = Uri.parse('https://pub.dev/api/packages/$name');
var response = await getCall(uri, retries: 3);
if (response.statusCode != 200) {
return false;
}
Expand All @@ -26,6 +26,20 @@ class Pub {
.contains(version);
}

Future<http.Response> getCall(Uri uri, {required int retries}) async {
for (var i = 0; i < retries + 1; i++) {
try {
var response = await httpClient.get(uri);
return response;
} catch (e) {
if (i >= retries) {
rethrow;
}
}
}
throw AssertionError('This should be unreachable');
}

void close() {
_httpClient?.close();
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/firehose/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: firehose
description: A tool to automate publishing of Pub packages from GitHub actions.
version: 0.3.32
version: 0.3.33
repository: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose

environment:
Expand Down

0 comments on commit 805ab4f

Please sign in to comment.