error when error in best selling

This commit is contained in:
Cat /dev/Nulo 2024-06-23 14:06:50 -03:00
parent d00cdc6bba
commit d495acfc9d
2 changed files with 23 additions and 7 deletions

View file

@ -2,6 +2,7 @@ use super::now_sec;
use super::supermercado::Supermercado; use super::supermercado::Supermercado;
use super::AutoArgs; use super::AutoArgs;
use super::AutoTelegram; use super::AutoTelegram;
use crate::best_selling;
use crate::db::Db; use crate::db::Db;
use crate::scraper::Scraper; use crate::scraper::Scraper;
use futures::Future; use futures::Future;
@ -70,6 +71,27 @@ impl Auto {
Ok(()) Ok(())
} }
pub async fn download_best_selling(&self) -> anyhow::Result<()> {
// let best_selling: Vec<best_selling::BestSellingRecord> =
match self
.inform_time(
"Downloaded best selling",
best_selling::get_all_best_selling(&self.db),
)
.await
{
Ok(best_selling) => {
self.db.save_best_selling(best_selling).await?;
}
Err(err) => {
self.inform(&format!("FAILED best selling: {:?}", err))
.await
}
}
Ok(())
}
pub async fn inform_time<T: Future<Output = R>, R>(&self, msg: &str, action: T) -> R { pub async fn inform_time<T: Future<Output = R>, R>(&self, msg: &str, action: T) -> R {
let t0 = now_sec(); let t0 = now_sec();
let res = action.await; let res = action.await;

View file

@ -256,13 +256,7 @@ async fn auto_cli(args: AutoArgs) -> anyhow::Result<()> {
future::try_join_all(handles).await?; future::try_join_all(handles).await?;
auto.inform("[auto] Download supermercados finished").await; auto.inform("[auto] Download supermercados finished").await;
let best_selling = auto auto.download_best_selling().await?;
.inform_time(
"Downloaded best selling",
best_selling::get_all_best_selling(&auto.db),
)
.await?;
auto.db.save_best_selling(best_selling).await?;
Ok(()) Ok(())
} }