Skip to content

Commit

Permalink
fixed: 115分段离线
Browse files Browse the repository at this point in the history
  • Loading branch information
zhifengle committed Oct 14, 2022
1 parent 5d882a8 commit 398972e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clap::{arg, Command};

pub fn build_app() -> Command<'static> {
let app = Command::new("rss2pan")
.version("0.0.1")
.version("0.1.0")
.about("rss to pan")
// .arg(arg!(-r --rss [rss] "rss json").default_value("rss.json"))
.arg(arg!(-u --url [url] "rss url"))
Expand Down
60 changes: 31 additions & 29 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,35 +108,37 @@ async fn execute_rss_task(
if item_list.len() == 0 {
return Ok(());
}
let tasks: Vec<&str> = item_list.iter().map(|item| &*item.magnet).collect();
// @TODO 并行?
// https://stackoverflow.com/questions/51044467/how-can-i-perform-parallel-asynchronous-http-get-requests-with-reqwest
let res = yiyiwu.add_batch_task(&tasks, config.cid.clone()).await?;
match res.errcode {
0 => {
log::info!(
"[115] [{}] [{}] add {} tasks",
config.name,
config.url,
item_list.len()
);
service.save_items(&item_list, true)?;
}
911 => {
log::error!("[115] response {:?}", res);
return Err(anyhow::format_err!("115 abnoraml operation"));
}
10004 => {
log::warn!("[115] wrong links");
}
10008 => {
log::warn!("[115] task exist");
service.save_items(&item_list, true)?;
}
_ => {
log::error!("[115] response {:?}", res);
}
};
for chunk in item_list.chunks(200) {
let tasks: Vec<&str> = chunk.iter().map(|item| &*item.magnet).collect();
// @TODO 并行?
// https://stackoverflow.com/questions/51044467/how-can-i-perform-parallel-asynchronous-http-get-requests-with-reqwest
let res = yiyiwu.add_batch_task(&tasks, config.cid.clone()).await?;
match res.errcode {
0 => {
log::info!(
"[115] [{}] [{}] add {} tasks",
config.name,
config.url,
chunk.len()
);
service.save_items(chunk, true)?;
}
911 => {
log::error!("[115] response {:?}", res);
return Err(anyhow::format_err!("115 abnoraml operation"));
}
10004 => {
log::warn!("[115] wrong links");
}
10008 => {
log::warn!("[115] task exist");
service.save_items(chunk, true)?;
}
_ => {
log::error!("[115] response {:?}", res);
}
};
}
}

Ok(())
Expand Down

0 comments on commit 398972e

Please sign in to comment.