Skip to content

Commit

Permalink
error when error in best selling
Browse files Browse the repository at this point in the history
  • Loading branch information
catdevnull committed Jun 23, 2024
1 parent d00cdc6 commit d495acf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
22 changes: 22 additions & 0 deletions scraper-rs/src/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::now_sec;
use super::supermercado::Supermercado;
use super::AutoArgs;
use super::AutoTelegram;
use crate::best_selling;
use crate::db::Db;
use crate::scraper::Scraper;
use futures::Future;
Expand Down Expand Up @@ -70,6 +71,27 @@ impl Auto {
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 {
let t0 = now_sec();
let res = action.await;
Expand Down
8 changes: 1 addition & 7 deletions scraper-rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,7 @@ async fn auto_cli(args: AutoArgs) -> anyhow::Result<()> {
future::try_join_all(handles).await?;
auto.inform("[auto] Download supermercados finished").await;

let best_selling = auto
.inform_time(
"Downloaded best selling",
best_selling::get_all_best_selling(&auto.db),
)
.await?;
auto.db.save_best_selling(best_selling).await?;
auto.download_best_selling().await?;

Ok(())
}
Expand Down

0 comments on commit d495acf

Please sign in to comment.