mirror of
https://github.com/n08i40k/schedule-parser-rusted.git
synced 2025-12-06 09:47:50 +03:00
feat(downloader): add retry-mechanism for querying uri from yandex-cloud api (#18)
This commit is contained in:
@@ -46,6 +46,9 @@ pub mod error {
|
|||||||
/// problems with the Yandex Cloud Function invocation.
|
/// problems with the Yandex Cloud Function invocation.
|
||||||
#[display("An error occurred during the request to the Yandex Cloud API: {_0}")]
|
#[display("An error occurred during the request to the Yandex Cloud API: {_0}")]
|
||||||
RequestFailed(reqwest::Error),
|
RequestFailed(reqwest::Error),
|
||||||
|
|
||||||
|
#[display("Unable to fetch Uri in 3 retries")]
|
||||||
|
UriFetchFailed,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Errors that may occur during the creation of a schedule snapshot.
|
/// Errors that may occur during the creation of a schedule snapshot.
|
||||||
@@ -144,18 +147,40 @@ impl Updater {
|
|||||||
async fn query_url(api_key: &str, func_id: &str) -> Result<String, QueryUrlError> {
|
async fn query_url(api_key: &str, func_id: &str) -> Result<String, QueryUrlError> {
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
|
|
||||||
let uri = client
|
let uri = {
|
||||||
.post(format!(
|
let mut uri = String::new();
|
||||||
"https://functions.yandexcloud.net/{}?integration=raw",
|
let mut counter = 0;
|
||||||
func_id
|
|
||||||
))
|
loop {
|
||||||
.header("Authorization", format!("Api-Key {}", api_key))
|
if counter == 3 {
|
||||||
.send()
|
return Err(QueryUrlError::UriFetchFailed);
|
||||||
.await
|
}
|
||||||
.map_err(QueryUrlError::RequestFailed)?
|
|
||||||
.text()
|
counter += 1;
|
||||||
.await
|
|
||||||
.map_err(QueryUrlError::RequestFailed)?;
|
uri = client
|
||||||
|
.post(format!(
|
||||||
|
"https://functions.yandexcloud.net/{}?integration=raw",
|
||||||
|
func_id
|
||||||
|
))
|
||||||
|
.header("Authorization", format!("Api-Key {}", api_key))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map_err(QueryUrlError::RequestFailed)?
|
||||||
|
.text()
|
||||||
|
.await
|
||||||
|
.map_err(QueryUrlError::RequestFailed)?;
|
||||||
|
|
||||||
|
if uri.is_empty() {
|
||||||
|
log::warn!("[{}] Unable to get uri! Retrying in 5 seconds...", counter);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
uri
|
||||||
|
};
|
||||||
|
|
||||||
Ok(format!("https://politehnikum-eng.ru{}", uri.trim()))
|
Ok(format!("https://politehnikum-eng.ru{}", uri.trim()))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user