|
1 | 1 | use actix_rt::spawn; |
| 2 | +use actix_rt::time::sleep; |
2 | 3 | use libflate::gzip; |
3 | 4 | use std::collections::hash_map::DefaultHasher; |
4 | 5 | use std::fs::File; |
@@ -99,21 +100,37 @@ fn copy_cached_to_opened_file(source: &Path, outfile: &mut impl std::io::Write) |
99 | 100 | } |
100 | 101 |
|
101 | 102 | async fn download_url_to_path(client: &awc::Client, url: &str, path: &Path) { |
102 | | - let mut resp = client.get(url).send().await.unwrap_or_else(|err| { |
103 | | - let path = make_url_path(url); |
104 | | - panic!( |
105 | | - "We need to download external frontend dependencies to build the static frontend. \n\ |
106 | | - Could not download static asset. You can manually download the file with: \n\ |
107 | | - curl {url:?} > {path:?} \n\ |
108 | | - {err}" |
109 | | - ) |
110 | | - }); |
111 | | - if resp.status() != 200 { |
112 | | - panic!("Received {} status code from {}", resp.status(), url); |
| 103 | + let mut attempt = 1; |
| 104 | + let max_attempts = 2; |
| 105 | + |
| 106 | + loop { |
| 107 | + match client.get(url).send().await { |
| 108 | + Ok(mut resp) => { |
| 109 | + if resp.status() != 200 { |
| 110 | + panic!("Received {} status code from {}", resp.status(), url); |
| 111 | + } |
| 112 | + let bytes = resp.body().limit(128 * 1024 * 1024).await.unwrap(); |
| 113 | + std::fs::write(path, &bytes) |
| 114 | + .expect("Failed to write external frontend dependency to local file"); |
| 115 | + break; |
| 116 | + } |
| 117 | + Err(err) => { |
| 118 | + if attempt >= max_attempts { |
| 119 | + let path = make_url_path(url); |
| 120 | + panic!( |
| 121 | + "We need to download external frontend dependencies to build the static frontend. \n\ |
| 122 | + Could not download static asset after {} attempts. You can manually download the file with: \n\ |
| 123 | + curl {url:?} > {path:?} \n\ |
| 124 | + {err}", |
| 125 | + max_attempts |
| 126 | + ); |
| 127 | + } |
| 128 | + sleep(Duration::from_secs(1)).await; |
| 129 | + println!("cargo:warning=Retrying download of {url} after {err}."); |
| 130 | + attempt += 1; |
| 131 | + } |
| 132 | + } |
113 | 133 | } |
114 | | - let bytes = resp.body().limit(128 * 1024 * 1024).await.unwrap(); |
115 | | - std::fs::write(path, &bytes) |
116 | | - .expect("Failed to write external frontend dependency to local file"); |
117 | 134 | } |
118 | 135 |
|
119 | 136 | // Given a filename, creates a new unique filename based on the file contents |
|
0 commit comments