Skip to content

chore(authenticator): fix authenticator task being dropped #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/tasks/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,25 @@ impl Authenticator {
}

/// Spawns a task that periodically fetches a new token every 300 seconds.
pub async fn spawn(self) -> JoinHandle<()> {
pub fn spawn(self) -> JoinHandle<()> {
let interval = self.config.oauth_token_refresh_interval;

tokio::spawn(async move {
let handle: JoinHandle<()> = tokio::spawn(async move {
loop {
tokio::time::sleep(tokio::time::Duration::from_secs(interval)).await;
tracing::info!("Refreshing oauth token");
self.authenticate().await.unwrap();
match self.authenticate().await {
Ok(_) => {
tracing::info!("Successfully refreshed oauth token");
}
Err(e) => {
tracing::error!(%e, "Failed to refresh oauth token");
}
};
let _sleep = tokio::time::sleep(tokio::time::Duration::from_secs(interval)).await;
}
})
});

handle
}
}

Expand Down
Loading