@@ -35,48 +35,50 @@ impl Repo {
35
35
Self ( Cow :: Borrowed ( s) )
36
36
}
37
37
38
- pub ( super ) fn artifact_for_commit (
38
+ pub ( super ) async fn artifact_for_commit (
39
39
self ,
40
40
series : Series ,
41
41
commit : Commit ,
42
42
filename : impl AsRef < Utf8Path > ,
43
43
downloader : & DownloadConfig ,
44
44
) -> anyhow:: Result < BuildomatArtifact > {
45
45
let filename = filename. as_ref ( ) ;
46
- let sha256 = self . get_sha256 ( & series, & commit, filename, downloader) ?;
46
+ let sha256 =
47
+ self . get_sha256 ( & series, & commit, filename, downloader) . await ?;
47
48
48
49
Ok ( BuildomatArtifact { repo : self , series, commit, sha256 } )
49
50
}
50
51
51
- pub ( super ) fn get_branch_head (
52
+ pub ( super ) async fn get_branch_head (
52
53
& self ,
53
54
branch : & str ,
54
55
) -> anyhow:: Result < Commit > {
55
- ( || {
56
+ async {
56
57
let uri = format ! ( "{BASE_URI}/branch/{self}/{branch}" ) ;
57
- let client = reqwest:: blocking :: ClientBuilder :: new ( )
58
+ let client = reqwest:: ClientBuilder :: new ( )
58
59
. timeout ( Duration :: from_secs ( 5 ) )
59
60
. build ( ) ?;
60
61
let req = client. get ( uri) . build ( ) ?;
61
- let rsp = client. execute ( req) ?;
62
+ let rsp = client. execute ( req) . await ?;
62
63
let status = rsp. status ( ) ;
63
64
anyhow:: ensure!( status. is_success( ) , "HTTP status: {status}" ) ;
64
- let bytes = rsp. bytes ( ) ?;
65
+ let bytes = rsp. bytes ( ) . await ?;
65
66
str_from_bytes ( & bytes) ?. parse :: < Commit > ( )
66
- } ) ( )
67
+ }
68
+ . await
67
69
. with_context ( || {
68
70
format ! ( "Failed to determine HEAD commit for {self}@{branch}" )
69
71
} )
70
72
}
71
73
72
- fn get_sha256 (
74
+ async fn get_sha256 (
73
75
& self ,
74
76
series : & Series ,
75
77
commit : & Commit ,
76
78
filename : & Utf8Path ,
77
79
downloader : & DownloadConfig ,
78
80
) -> anyhow:: Result < String > {
79
- ( || {
81
+ async {
80
82
let filename = filename
81
83
. file_name ( )
82
84
. ok_or_else ( || {
@@ -105,9 +107,9 @@ impl Repo {
105
107
)
106
108
} ) ?;
107
109
let uri = format ! ( "{BASE_URI}/file/{self}/{series}/{commit}/{filename}.sha256.txt" ) ;
108
- let bytes = downloader. download_buildomat_uri ( & uri) ?;
110
+ let bytes = downloader. download_buildomat_uri ( & uri) . await ?;
109
111
str_from_bytes ( & bytes) . map ( String :: from)
110
- } ) ( ) . with_context ( || {
112
+ } . await . with_context ( || {
111
113
format ! ( "Failed to get SHA256 for {self}@{commit}, series: {series}, file: {filename})" )
112
114
} )
113
115
}
@@ -206,7 +208,7 @@ impl super::DownloadConfig {
206
208
/// retry duration. This retry logic serves as a mechanism for PHD to wait
207
209
/// for an artifact we expect to exist to be published, when the build that
208
210
/// publishes that artifact is still in progress.
209
- pub ( super ) fn download_buildomat_uri (
211
+ pub ( super ) async fn download_buildomat_uri (
210
212
& self ,
211
213
uri : & str ,
212
214
) -> anyhow:: Result < bytes:: Bytes > {
@@ -215,10 +217,9 @@ impl super::DownloadConfig {
215
217
%uri,
216
218
"Downloading file from Buildomat..." ,
217
219
) ;
218
- let client = reqwest:: blocking:: ClientBuilder :: new ( )
219
- . timeout ( self . timeout )
220
- . build ( ) ?;
221
- let try_download = || {
220
+ let client =
221
+ reqwest:: ClientBuilder :: new ( ) . timeout ( self . timeout ) . build ( ) ?;
222
+ let try_download = || async {
222
223
let request = client
223
224
. get ( uri)
224
225
. build ( )
@@ -229,7 +230,9 @@ impl super::DownloadConfig {
229
230
230
231
let response = client
231
232
. execute ( request)
233
+ . await
232
234
. map_err ( |e| backoff:: Error :: transient ( e. into ( ) ) ) ?;
235
+
233
236
if !response. status ( ) . is_success ( ) {
234
237
// when downloading a file from buildomat, we currently retry
235
238
// all errors, since buildomat returns 500s when an artifact
@@ -252,17 +255,15 @@ impl super::DownloadConfig {
252
255
) ;
253
256
} ;
254
257
255
- let bytes = backoff:: retry_notify (
258
+ let bytes = backoff:: future :: retry_notify (
256
259
self . buildomat_backoff . clone ( ) ,
257
260
try_download,
258
261
log_retry,
259
262
)
260
- . map_err ( |e| match e {
261
- backoff:: Error :: Permanent ( e) => e,
262
- backoff:: Error :: Transient { err, .. } => err,
263
- } )
263
+ . await
264
264
. with_context ( || format ! ( "Failed to download '{uri}' from Buildomat" ) ) ?
265
- . bytes ( ) ?;
265
+ . bytes ( )
266
+ . await ?;
266
267
267
268
Ok ( bytes)
268
269
}
0 commit comments