retry the remaining plain schedules with backon
This commit is contained in:
parent
e21a03d6ff
commit
ed76419be7
7 changed files with 132 additions and 64 deletions
|
|
@ -12,9 +12,7 @@ use std::collections::HashMap;
|
|||
use std::path::Path;
|
||||
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, TODO_SOCKET_RETRY, agent_socket, init_tracing};
|
||||
use source::ForgejoSource;
|
||||
use tracing::{debug, info, warn};
|
||||
|
|
@ -41,22 +39,13 @@ async fn forgejo_loop(state_dir: String, socket: std::path::PathBuf) {
|
|||
// Retry reading the token to handle races where the agent's fetch of
|
||||
// it from the swarm secret store lands after this unit starts, or where
|
||||
// a parent-container chown briefly makes the file unreadable.
|
||||
let mut token = {
|
||||
let mut attempts = 0u32;
|
||||
loop {
|
||||
if let Some(t) = hive_forge_notify::read_first_token(&token_paths) {
|
||||
break t;
|
||||
}
|
||||
debug!(?token_paths, "forge_notify: no forge token yet");
|
||||
attempts += 1;
|
||||
if attempts >= TOKEN_RETRY_MAX {
|
||||
debug!(
|
||||
"forge_notify: token not available after {TOKEN_RETRY_MAX} retries — disabled"
|
||||
);
|
||||
return;
|
||||
}
|
||||
tokio::time::sleep(Duration::from_secs(TOKEN_RETRY_SECS)).await;
|
||||
}
|
||||
let Some(mut token) = wait_for_token("forge token", || async {
|
||||
hive_forge_notify::read_first_token(&token_paths)
|
||||
})
|
||||
.await
|
||||
else {
|
||||
debug!(?token_paths, "forge_notify: token not available — disabled");
|
||||
return;
|
||||
};
|
||||
|
||||
let Some(mut source) = ForgejoSource::new(&forge_url, &token) else {
|
||||
|
|
|
|||
|
|
@ -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