tangled
alpha
login
or
join now
t1c.dev
/
rocksky
forked from
rocksky.app/rocksky
2
fork
atom
A decentralized music tracking and discovery platform built on AT Protocol 🎵
2
fork
atom
overview
issues
pulls
pipelines
[spotify] correctly handle errors
tsiry-sandratraina.com
10 months ago
2b3cc142
0dcb321e
+13
-8
1 changed file
expand all
collapse all
unified
split
crates
spotify
src
main.rs
+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
442
-
thread::sleep(std::time::Duration::from_millis(500));
442
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
449
-
current_song.progress_ms = Some(current_song.progress_ms.unwrap_or(0) + 500);
450
450
-
cache_clone.setex(&format!("{}:current", spotify_email_clone), &serde_json::to_string(¤t_song)?, 16)?;
451
451
-
thread::sleep(std::time::Duration::from_millis(500));
449
449
+
current_song.progress_ms = Some(current_song.progress_ms.unwrap_or(0) + 800);
450
450
+
match cache_clone.setex(&format!("{}:current", spotify_email_clone), &serde_json::to_string(¤t_song)?, 16) {
451
451
+
Ok(_) => {},
452
452
+
Err(e) => {
453
453
+
println!("{} redis error: {}", format!("[{}]", spotify_email_clone).bright_green(), e.to_string().bright_red());
454
454
+
}
455
455
+
}
456
456
+
thread::sleep(std::time::Duration::from_millis(800));
452
457
continue;
453
458
}
454
459
}
455
460
continue;
456
461
}
457
462
458
458
-
if let Some(cached) = cache_clone.get(&spotify_email_clone)? {
463
463
+
if let Ok(Some(cached)) = cache_clone.get(&spotify_email_clone) {
459
464
if cached == "No content" {
460
460
-
thread::sleep(std::time::Duration::from_millis(500));
465
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
466
-
println!("{} {}", format!("[{}]", spotify_email_clone).bright_green(), e.to_string().bright_red());
471
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
472
-
thread::sleep(std::time::Duration::from_millis(500));
477
477
+
thread::sleep(std::time::Duration::from_millis(800));
473
478
}
474
479
Ok::<(), Error>(())
475
480
});