feat: add token task
This commit is contained in:
parent
a515976d43
commit
ae05363a30
|
@ -283,6 +283,10 @@ impl State {
|
|||
let task_state = Arc::clone(&state);
|
||||
self::task::stream_status::start_task(task_state).await;
|
||||
|
||||
// start token refresh task
|
||||
let task_state = Arc::clone(&state);
|
||||
self::task::tokens::start_task(task_state).await;
|
||||
|
||||
println!("initialised");
|
||||
|
||||
Ok(state)
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
pub mod stream_status;
|
||||
pub mod tokens;
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
use chrono::Duration;
|
||||
use crate::app::State;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub async fn start_task(state: Arc<State>) {
|
||||
tokio::task::spawn(async move {
|
||||
loop {
|
||||
if let Err(e) = state.twitch.bot_token().await {
|
||||
eprintln!("could not get bot token: {:?}", e);
|
||||
}
|
||||
|
||||
if let Err(e) = state.twitch.user_token().await {
|
||||
eprintln!("could not get user token: {:?}", e);
|
||||
}
|
||||
|
||||
tokio::time::sleep(Duration::minutes(15).to_std().unwrap()).await;
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue