Skip to content

Commit

Permalink
Merge pull request #115 from tsirysndr/fix/scrobble
Browse files Browse the repository at this point in the history
fix(rocksky): run rocksky scrobbling in another async thread
  • Loading branch information
tsirysndr authored Feb 7, 2025
2 parents 18ec5f9 + 2860177 commit 99b3687
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions crates/rocksky/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ pub async fn scrobble(track: Track, album: Album) -> Result<(), Error> {
.send()
.await?;
println!("Scrobbled: {}", response.status());

if !response.status().is_success() {
println!("Failed to scrobble: {}", response.text().await?);
}

Ok(())
}

Expand Down
15 changes: 11 additions & 4 deletions crates/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,17 @@ pub extern "C" fn start_broker() {
SimpleBroker::publish(track.clone());

if previous_index != rb::playlist::index() {
match rt.block_on(scrobble(track.clone(), pool.clone())) {
Ok(_) => {}
Err(e) => eprintln!("{}", e),
}
let cloned_pool = pool.clone();
thread::spawn(move || {
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
match rt.block_on(scrobble(track.clone(), cloned_pool.clone())) {
Ok(_) => {}
Err(e) => eprintln!("{}", e),
}
});
}
previous_index = rb::playlist::index();
}
Expand Down

0 comments on commit 99b3687

Please sign in to comment.