mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-17 16:16:37 +00:00
Fix launch_baseline_find_tasks
: Retry on rate limit
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
53b3c02b3b
commit
6b3e38453f
1 changed files with 20 additions and 11 deletions
|
@ -1,4 +1,4 @@
|
||||||
use std::{borrow::Cow, fmt, iter, path::Path, sync::Arc};
|
use std::{borrow::Cow, fmt, iter, path::Path, sync::Arc, time::Duration};
|
||||||
|
|
||||||
use binstalk_git_repo_api::gh_api_client::{GhApiError, GhReleaseArtifact, GhReleaseArtifactUrl};
|
use binstalk_git_repo_api::gh_api_client::{GhApiError, GhReleaseArtifact, GhReleaseArtifactUrl};
|
||||||
use compact_str::{CompactString, ToCompactString};
|
use compact_str::{CompactString, ToCompactString};
|
||||||
|
@ -6,6 +6,7 @@ use either::Either;
|
||||||
use leon::Template;
|
use leon::Template;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use strum::IntoEnumIterator;
|
use strum::IntoEnumIterator;
|
||||||
|
use tokio::time::sleep;
|
||||||
use tracing::{debug, info, trace, warn};
|
use tracing::{debug, info, trace, warn};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -14,6 +15,8 @@ use crate::{
|
||||||
SignaturePolicy, SignatureVerifier, TargetDataErased,
|
SignaturePolicy, SignatureVerifier, TargetDataErased,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static DEFAULT_GH_API_RETRY_DURATION: Duration = Duration::from_secs(1);
|
||||||
|
|
||||||
pub(crate) mod hosting;
|
pub(crate) mod hosting;
|
||||||
|
|
||||||
pub struct GhCrateMeta {
|
pub struct GhCrateMeta {
|
||||||
|
@ -102,19 +105,25 @@ impl GhCrateMeta {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(artifact) = gh_release_artifact {
|
if let Some(artifact) = gh_release_artifact {
|
||||||
match get_gh_release_artifact_url(gh_api_client, artifact).await {
|
loop {
|
||||||
|
match get_gh_release_artifact_url(gh_api_client.clone(), artifact.clone())
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(Some(artifact_url)) => {
|
Ok(Some(artifact_url)) => {
|
||||||
resolved.gh_release_artifact_url = Some(artifact_url);
|
resolved.gh_release_artifact_url = Some(artifact_url);
|
||||||
return Ok(Some(resolved));
|
return Ok(Some(resolved));
|
||||||
}
|
}
|
||||||
Ok(None) => return Ok(None),
|
Ok(None) => return Ok(None),
|
||||||
|
|
||||||
Err(GhApiError::RateLimit { .. }) => (),
|
Err(GhApiError::RateLimit { retry_after }) => {
|
||||||
Err(GhApiError::Unauthorized) if !is_repo_private => (),
|
sleep(retry_after.unwrap_or(DEFAULT_GH_API_RETRY_DURATION)).await;
|
||||||
|
}
|
||||||
|
Err(GhApiError::Unauthorized) if !is_repo_private => break,
|
||||||
|
|
||||||
Err(err) => return Err(err.into()),
|
Err(err) => return Err(err.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(Box::pin(client.remote_gettable(url))
|
Ok(Box::pin(client.remote_gettable(url))
|
||||||
.await?
|
.await?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue