-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: convert extension install to async (#3815)
- Loading branch information
1 parent
931f4fa
commit cefa5b0
Showing
12 changed files
with
103 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use crate::http::retryable::Retryable; | ||
use reqwest::StatusCode; | ||
use thiserror::Error; | ||
|
||
// reqwest::Error's fmt::Display appends the error descriptions of all sources. | ||
// For this reason, it is not marked as #[source] here, so that we don't | ||
// display the error descriptions of all sources repeatedly. | ||
#[derive(Error, Debug)] | ||
#[error("{}", .0)] | ||
pub struct WrappedReqwestError(pub reqwest::Error); | ||
|
||
impl Retryable for WrappedReqwestError { | ||
fn is_retryable(&self) -> bool { | ||
let err = &self.0; | ||
err.is_timeout() | ||
|| err.is_connect() | ||
|| matches!( | ||
err.status(), | ||
Some( | ||
StatusCode::INTERNAL_SERVER_ERROR | ||
| StatusCode::BAD_GATEWAY | ||
| StatusCode::SERVICE_UNAVAILABLE | ||
| StatusCode::GATEWAY_TIMEOUT | ||
| StatusCode::TOO_MANY_REQUESTS | ||
) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::error::reqwest::WrappedReqwestError; | ||
use crate::http::retryable::Retryable; | ||
use backoff::exponential::ExponentialBackoff; | ||
use backoff::future::retry; | ||
use backoff::SystemClock; | ||
use reqwest::Response; | ||
use url::Url; | ||
|
||
pub async fn get_with_retries( | ||
url: Url, | ||
retry_policy: ExponentialBackoff<SystemClock>, | ||
) -> Result<Response, WrappedReqwestError> { | ||
let operation = || async { | ||
let response = reqwest::get(url.clone()) | ||
.await | ||
.and_then(|resp| resp.error_for_status()) | ||
.map_err(WrappedReqwestError); | ||
match response { | ||
Ok(doc) => Ok(doc), | ||
Err(e) if e.is_retryable() => Err(backoff::Error::transient(e)), | ||
Err(e) => Err(backoff::Error::permanent(e)), | ||
} | ||
}; | ||
retry(retry_policy, operation).await | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod get; | ||
pub mod retryable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub trait Retryable { | ||
fn is_retryable(&self) -> bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters