reintentar pedidos de API a Jumbo

This commit is contained in:
Cat /dev/Nulo 2024-01-14 10:52:12 -03:00
parent e97b355715
commit 3396a433e5

View file

@ -1,12 +1,13 @@
use std::str::FromStr; use std::str::FromStr;
use anyhow::Context; use anyhow::Context;
use futures::TryFutureExt;
use reqwest::Url; use reqwest::Url;
use serde::Deserialize; use serde::Deserialize;
use simple_error::bail; use simple_error::bail;
use crate::sites::common; use crate::sites::common;
use crate::PrecioPoint; use crate::{do_request, get_retry_policy, PrecioPoint};
use super::vtex; use super::vtex;
@ -23,17 +24,15 @@ async fn get_ean_from_search(
client: &reqwest::Client, client: &reqwest::Client,
retailer_sku: String, retailer_sku: String,
) -> anyhow::Result<String> { ) -> anyhow::Result<String> {
let s = client let url = {
.get({ let mut url =
let mut url = Url::from_str("https://www.jumbo.com.ar/api/catalog_system/pub/products/search")
Url::from_str("https://www.jumbo.com.ar/api/catalog_system/pub/products/search") .unwrap();
.unwrap(); url.set_query(Some(&format!("fq=skuId:{}", retailer_sku)));
url.set_query(Some(&format!("fq=skuId:{}", retailer_sku))); url
url };
}) let s = get_retry_policy()
.send() .retry(|| do_request(client, url.as_str()).and_then(|r| r.text()))
.await?
.text()
.await?; .await?;
let ean = { let ean = {
let search: Vec<JumboSearch> = serde_json::from_str(&s)?; let search: Vec<JumboSearch> = serde_json::from_str(&s)?;