chore: 使用 tokio::spawn 运行主任务 (#237)

This commit is contained in:
ᴀᴍᴛᴏᴀᴇʀ
2025-02-01 18:47:27 +08:00
committed by GitHub
parent cc7f773300
commit 51672e8607
7 changed files with 50 additions and 33 deletions
+27 -25
View File
@@ -31,35 +31,37 @@ async fn main() {
let mut anchor = chrono::Local::now().date_naive();
let bili_client = BiliClient::new();
let params = build_params();
loop {
'inner: {
match bili_client.wbi_img().await.map(|wbi_img| wbi_img.into()) {
Ok(Some(mixin_key)) => bilibili::set_global_mixin_key(mixin_key),
Ok(_) => {
error!("解析 mixin key 失败,等待下一轮执行");
break 'inner;
tokio::spawn(async move {
loop {
'inner: {
match bili_client.wbi_img().await.map(|wbi_img| wbi_img.into()) {
Ok(Some(mixin_key)) => bilibili::set_global_mixin_key(mixin_key),
Ok(_) => {
error!("解析 mixin key 失败,等待下一轮执行");
break 'inner;
}
Err(e) => {
error!("获取 mixin key 遇到错误:{e},等待下一轮执行");
break 'inner;
}
};
if anchor != chrono::Local::now().date_naive() {
if let Err(e) = bili_client.check_refresh().await {
error!("检查刷新 Credential 遇到错误:{e},等待下一轮执行");
break 'inner;
}
anchor = chrono::Local::now().date_naive();
}
Err(e) => {
error!("获取 mixin key 遇到错误:{e},等待下一轮执行");
break 'inner;
for (args, path) in &params {
if let Err(e) = process_video_list(*args, &bili_client, path, &connection).await {
error!("处理过程遇到错误:{e}");
}
}
};
if anchor != chrono::Local::now().date_naive() {
if let Err(e) = bili_client.check_refresh().await {
error!("检查刷新 Credential 遇到错误:{e},等待下一轮执行");
break 'inner;
}
anchor = chrono::Local::now().date_naive();
info!("本轮任务执行完毕,等待下一轮执行");
}
for (args, path) in &params {
if let Err(e) = process_video_list(*args, &bili_client, path, &connection).await {
error!("处理过程遇到错误:{e}");
}
}
info!("本轮任务执行完毕,等待下一轮执行");
time::sleep(time::Duration::from_secs(CONFIG.interval)).await;
}
time::sleep(time::Duration::from_secs(CONFIG.interval)).await;
}
});
}
fn build_params() -> Vec<(Args<'static>, &'static PathBuf)> {