mirror of
https://github.com/catdevnull/preciazo.git
synced 2024-11-25 19:16:19 +00:00
no reintentar si no se encontró
This commit is contained in:
parent
a697f5cb0c
commit
26b9f4b17f
3 changed files with 12 additions and 5 deletions
|
@ -178,13 +178,17 @@ pub fn get_retry_policy() -> again::RetryPolicy {
|
|||
.with_jitter(true)
|
||||
}
|
||||
|
||||
pub fn retry_if_wasnt_not_found(err: &reqwest::Error) -> bool {
|
||||
!err.status().is_some_and(|s| s == StatusCode::NOT_FOUND)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(client))]
|
||||
async fn fetch_and_parse(
|
||||
client: &reqwest::Client,
|
||||
url: String,
|
||||
) -> Result<PrecioPoint, anyhow::Error> {
|
||||
let body = get_retry_policy()
|
||||
.retry(|| do_request(client, &url))
|
||||
.retry_if(|| do_request(client, &url), retry_if_wasnt_not_found)
|
||||
.await?
|
||||
.text()
|
||||
.await
|
||||
|
|
|
@ -3,7 +3,7 @@ use futures::{stream, StreamExt, TryFutureExt, TryStreamExt};
|
|||
use itertools::Itertools;
|
||||
use reqwest::Url;
|
||||
|
||||
use crate::{build_client, do_request, get_retry_policy, PrecioPoint};
|
||||
use crate::{build_client, do_request, get_retry_policy, retry_if_wasnt_not_found, PrecioPoint};
|
||||
|
||||
pub fn parse(url: String, dom: &tl::VDom) -> Result<PrecioPoint, anyhow::Error> {
|
||||
let ean = dom
|
||||
|
@ -90,7 +90,10 @@ pub async fn get_urls() -> anyhow::Result<Vec<String>> {
|
|||
let client = &client;
|
||||
async move {
|
||||
let text = get_retry_policy()
|
||||
.retry(|| do_request(client, u.as_str()).and_then(|r| r.text()))
|
||||
.retry_if(
|
||||
|| do_request(client, u.as_str()).and_then(|r| r.text()),
|
||||
retry_if_wasnt_not_found,
|
||||
)
|
||||
.await?;
|
||||
let dom = tl::parse(&text, tl::ParserOptions::default())?;
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use serde::Deserialize;
|
|||
use simple_error::SimpleError;
|
||||
use tl::VDom;
|
||||
|
||||
use crate::{build_client, do_request, get_retry_policy};
|
||||
use crate::{build_client, do_request, get_retry_policy, retry_if_wasnt_not_found};
|
||||
|
||||
use super::common;
|
||||
|
||||
|
@ -128,7 +128,7 @@ pub async fn get_urls_from_sitemap(sitemaps: Vec<&str>) -> anyhow::Result<Vec<St
|
|||
let client = client;
|
||||
let url = url;
|
||||
let text = get_retry_policy()
|
||||
.retry(|| do_request(&client, &url))
|
||||
.retry_if(|| do_request(&client, &url), retry_if_wasnt_not_found)
|
||||
.await?
|
||||
.text()
|
||||
.await?;
|
||||
|
|
Loading…
Reference in a new issue