retry the remaining plain schedules with backon
This commit is contained in:
parent
e21a03d6ff
commit
ed76419be7
1 changed files with 132 additions and 64 deletions
|
|
@ -24,9 +24,7 @@ mod source;
|
|||
use std::collections::HashMap;
|
||||
use std::time::Duration;
|
||||
|
||||
use hive_forge_notify::notify::{
|
||||
POLL_INTERVAL_SECS, TOKEN_RETRY_MAX, TOKEN_RETRY_SECS, poll_once, resolve_own_login,
|
||||
};
|
||||
use hive_forge_notify::notify::{POLL_INTERVAL_SECS, poll_once, resolve_own_login, wait_for_token};
|
||||
use hive_forge_notify::{HTTP_TIMEOUT_SECS, agent_socket, init_tracing};
|
||||
use source::GithubSource;
|
||||
use tracing::{debug, info, warn};
|
||||
|
|
@ -50,20 +48,14 @@ async fn main() {
|
|||
/// common case for an agent that has the unit but no account.
|
||||
async fn github_loop(state_dir: String, socket: std::path::PathBuf) {
|
||||
let token_path = format!("{state_dir}/github-token");
|
||||
let mut attempts = 0u32;
|
||||
let token = loop {
|
||||
match tokio::fs::read_to_string(&token_path).await {
|
||||
Ok(t) if !t.trim().is_empty() => break t.trim().to_owned(),
|
||||
_ => debug!("forge_notify: no github token at {token_path} yet"),
|
||||
}
|
||||
attempts += 1;
|
||||
if attempts >= TOKEN_RETRY_MAX {
|
||||
debug!(
|
||||
"forge_notify: no github token after {TOKEN_RETRY_MAX} retries — github disabled"
|
||||
);
|
||||
return;
|
||||
}
|
||||
tokio::time::sleep(Duration::from_secs(TOKEN_RETRY_SECS)).await;
|
||||
let Some(token) = wait_for_token("github token", || async {
|
||||
let text = tokio::fs::read_to_string(&token_path).await.ok()?;
|
||||
Some(text.trim().to_owned()).filter(|t| !t.is_empty())
|
||||
})
|
||||
.await
|
||||
else {
|
||||
debug!("forge_notify: no github token at {token_path} — github disabled");
|
||||
return;
|
||||
};
|
||||
|
||||
let client = match reqwest::Client::builder()
|
||||
|
|
|
|||
Loading…
Reference in a new issue