Store 429 occurances globally

This commit is contained in:
blank X 2021-06-27 08:18:11 +07:00
parent 5b18b3e6d2
commit 4de4bb6e3d
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 11 additions and 7 deletions

View File

@ -123,7 +123,7 @@ async fn async_main() {
let video_mutex = Arc::new(Mutex::new(VecDeque::new())); let video_mutex = Arc::new(Mutex::new(VecDeque::new()));
let upload_semaphore = Arc::new(Semaphore::new(0)); let upload_semaphore = Arc::new(Semaphore::new(0));
let upload_mutex = Arc::new(Mutex::new(VecDeque::new())); let upload_mutex = Arc::new(Mutex::new(VecDeque::new()));
let query_lock = Arc::new(tokio::sync::Mutex::new(())); let query_mutex = Arc::new(tokio::sync::Mutex::new(1));
if !nodl { if !nodl {
let date_regex = Arc::new(Regex::new(r#" *\d{4}-\d{2}-\d{2} \d{2}:\d{2}$"#).unwrap()); let date_regex = Arc::new(Regex::new(r#" *\d{4}-\d{2}-\d{2} \d{2}:\d{2}$"#).unwrap());
for _ in 0..config::VIDEO_WORKERS { for _ in 0..config::VIDEO_WORKERS {
@ -172,14 +172,13 @@ async fn async_main() {
} }
let mutex = video_mutex.clone(); let mutex = video_mutex.clone();
let semaphore = video_semaphore.clone(); let semaphore = video_semaphore.clone();
let query_lock = query_lock.clone(); let query_mutex = query_mutex.clone();
let tclient = tclient.clone(); let tclient = tclient.clone();
let chat = chat.clone(); let chat = chat.clone();
tokio::task::spawn(async move { tokio::task::spawn(async move {
let mut waited = false; let mut waited = false;
let mut i = 1;
loop { loop {
let guard = query_lock.lock().await; let mut guard = query_mutex.lock().await;
match utils::get_video(&j).await { match utils::get_video(&j).await {
Ok(Some(i)) => { Ok(Some(i)) => {
let first_try_live = let first_try_live =
@ -190,9 +189,13 @@ async fn async_main() {
first_try_live, first_try_live,
)); ));
semaphore.add_permits(1); semaphore.add_permits(1);
*guard = 1;
break;
}
Ok(None) => {
*guard = 1;
break; break;
} }
Ok(None) => break,
Err(err) => { Err(err) => {
eprintln!("Failed to get video data: {:?}", err); eprintln!("Failed to get video data: {:?}", err);
waited = true; waited = true;
@ -202,8 +205,9 @@ async fn async_main() {
|| output.contains("too many request") || output.contains("too many request")
|| output.contains("technical difficult") || output.contains("technical difficult")
{ {
sleep(Duration::from_secs(i * 60 * 60)).await; sleep(Duration::from_secs(*guard * 60 * 60))
i += 1; .await;
*guard += 1;
continue; continue;
} else if err } else if err
.output .output