mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Add error handling and retry attempts
Handles cases where the segments fail to download and sometimes get stuck by introducing a timeout and retrying on failure.
This commit is contained in:
parent
c5940a240c
commit
240e5563a3
1 changed files with 49 additions and 2 deletions
|
|
@ -76,8 +76,55 @@ pub async fn download_segments(
|
||||||
let thread_count = count.clone();
|
let thread_count = count.clone();
|
||||||
join_set.spawn(async move {
|
join_set.spawn(async move {
|
||||||
for (i, segment) in thread_segments.into_iter().enumerate() {
|
for (i, segment) in thread_segments.into_iter().enumerate() {
|
||||||
let response = thread_client.get(&segment.url).send().await?;
|
let response_res = thread_client
|
||||||
let mut buf = response.bytes().await?.to_vec();
|
.get(&segment.url)
|
||||||
|
.timeout(Duration::from_secs(60u64))
|
||||||
|
.send()
|
||||||
|
.await;
|
||||||
|
let verfified_response = match response_res {
|
||||||
|
Ok(x) => x,
|
||||||
|
Err(y) => panic!("This is likely a netowrking error: {}", y),
|
||||||
|
};
|
||||||
|
let possible_error_in_response = verfified_response.bytes().await;
|
||||||
|
let mut buf = if let Ok(r) = possible_error_in_response {
|
||||||
|
r.to_vec()
|
||||||
|
} else {
|
||||||
|
debug!(
|
||||||
|
"Segment Failed to download: {}, retrying.",
|
||||||
|
num + (i * cpus)
|
||||||
|
);
|
||||||
|
let mut resp = thread_client
|
||||||
|
.get(&segment.url)
|
||||||
|
.timeout(Duration::from_secs(60u64))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.bytes()
|
||||||
|
.await;
|
||||||
|
if resp.is_err() {
|
||||||
|
let mut retry_ctr = 1;
|
||||||
|
loop {
|
||||||
|
debug!(
|
||||||
|
"Segment Failed to download: {}, retry {}.",
|
||||||
|
num + (i * cpus),
|
||||||
|
retry_ctr
|
||||||
|
);
|
||||||
|
resp = thread_client
|
||||||
|
.get(&segment.url)
|
||||||
|
.timeout(Duration::from_secs(60u64))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.bytes()
|
||||||
|
.await;
|
||||||
|
if resp.is_ok() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
retry_ctr += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resp.unwrap().to_vec()
|
||||||
|
};
|
||||||
|
|
||||||
buf = VariantSegment::decrypt(buf.borrow_mut(), segment.key)?.to_vec();
|
buf = VariantSegment::decrypt(buf.borrow_mut(), segment.key)?.to_vec();
|
||||||
debug!(
|
debug!(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue