Skip to content

Commit 81cb422

Browse files
committed
Fix start_jobs
1 parent 0049fe9 commit 81cb422

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

‎src/main.rs‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,19 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
8888

8989
fn start_jobs(state: Arc<RwLock<State>>) {
9090
tokio::spawn(async move {
91-
(state.write()).song_info = music::now_playing().await.ok();
91+
loop {
92+
match music::now_playing().await {
93+
Ok(info) => state.write().song_info = Some(info),
94+
Err(e) => eprintln!("failed to fetch now playing: {e}"),
95+
}
9296

93-
(state.write()).last_clash_battle = clash::last_battles()
94-
.await
95-
.expect("failed to get last clash battles")
96-
.first()
97-
.cloned();
97+
match clash::last_battles().await {
98+
Ok(battles) => state.write().last_clash_battle = battles.first().cloned(),
99+
Err(e) => eprintln!("failed to fetch clash battles: {e}"),
100+
}
98101

99-
tokio::time::sleep(Duration::from_secs(60)).await;
102+
tokio::time::sleep(Duration::from_secs(60)).await;
103+
}
100104
});
101105
}
102106

@@ -269,9 +273,7 @@ fn root(request: Request, state: Arc<RwLock<State>>) {
269273

270274
format!("I'm {where_i_am}.")
271275
}
272-
_ => {
273-
"I can't tell where either of us are right now, but I hope to see you soon!".to_string()
274-
}
276+
_ => "I can't tell where either of us are, but I hope to see you soon!".to_string(),
275277
};
276278
drop(my_location);
277279

0 commit comments

Comments
 (0)