A decentralized music tracking and discovery platform built on AT Protocol 🎵

[spotify] correctly handle errors

+13 -8
+13 -8
crates/spotify/src/main.rs
··· 439 439 } 440 440 if let Some(cached) = cache_clone.get(&format!("{}:current", spotify_email_clone))? { 441 441 if serde_json::from_str::<CurrentlyPlaying>(&cached).is_err() { 442 - thread::sleep(std::time::Duration::from_millis(500)); 442 + thread::sleep(std::time::Duration::from_millis(800)); 443 443 continue; 444 444 } 445 445 let mut current_song = serde_json::from_str::<CurrentlyPlaying>(&cached)?; 446 446 447 447 if let Some(item) = current_song.item.clone() { 448 448 if current_song.is_playing && current_song.progress_ms.unwrap_or(0) < item.duration_ms.into() { 449 - current_song.progress_ms = Some(current_song.progress_ms.unwrap_or(0) + 500); 450 - cache_clone.setex(&format!("{}:current", spotify_email_clone), &serde_json::to_string(&current_song)?, 16)?; 451 - thread::sleep(std::time::Duration::from_millis(500)); 449 + current_song.progress_ms = Some(current_song.progress_ms.unwrap_or(0) + 800); 450 + match cache_clone.setex(&format!("{}:current", spotify_email_clone), &serde_json::to_string(&current_song)?, 16) { 451 + Ok(_) => {}, 452 + Err(e) => { 453 + println!("{} redis error: {}", format!("[{}]", spotify_email_clone).bright_green(), e.to_string().bright_red()); 454 + } 455 + } 456 + thread::sleep(std::time::Duration::from_millis(800)); 452 457 continue; 453 458 } 454 459 } 455 460 continue; 456 461 } 457 462 458 - if let Some(cached) = cache_clone.get(&spotify_email_clone)? { 463 + if let Ok(Some(cached)) = cache_clone.get(&spotify_email_clone) { 459 464 if cached == "No content" { 460 - thread::sleep(std::time::Duration::from_millis(500)); 465 + thread::sleep(std::time::Duration::from_millis(800)); 461 466 continue; 462 467 } 463 468 match cache_clone.setex(&format!("{}:current", spotify_email_clone), &cached, 16) { 464 469 Ok(_) => {}, 465 470 Err(e) => { 466 - println!("{} {}", format!("[{}]", spotify_email_clone).bright_green(), e.to_string().bright_red()); 471 + println!("{} redis error: {}", format!("[{}]", spotify_email_clone).bright_green(), e.to_string().bright_red()); 467 472 } 468 473 } 469 474 } 470 475 471 476 472 - thread::sleep(std::time::Duration::from_millis(500)); 477 + thread::sleep(std::time::Duration::from_millis(800)); 473 478 } 474 479 Ok::<(), Error>(()) 475 480 });