swarm-controller: archive a destroyed agent's config repo, unarchive it when the name is created again
This commit is contained in:
parent
814edd1d67
commit
7beb1193f4
1 changed files with 197 additions and 3 deletions
36
swarm-controller/src/agent_config_repo.rs
Normal file
36
swarm-controller/src/agent_config_repo.rs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
//! A destroyed agent's config repo (`agent-configs/<agent>`): archived when the
|
||||
//! agent is declared `Destroyed`, so it stays readable but takes no more
|
||||
//! pushes or PRs, and unarchived when an agent of the same name is created
|
||||
//! again (`forge::Client::create_repo`).
|
||||
|
||||
use crate::routes::AppState;
|
||||
|
||||
/// Archive `agent`'s config repo. A failure is logged and does not stop the
|
||||
/// destroy, as in `agent_archetype::clear_on_destroy`: an agent that cannot be
|
||||
/// torn down is the larger harm, and declaring it destroyed again re-runs
|
||||
/// this.
|
||||
pub(crate) async fn archive_on_destroy(state: &AppState, hive: &str, agent: &str) {
|
||||
let Some(forge) = state.forge.get() else {
|
||||
tracing::warn!(
|
||||
hive,
|
||||
agent,
|
||||
"no forge access here, so the destroyed agent's config repo was left as it is"
|
||||
);
|
||||
return;
|
||||
};
|
||||
match forge.set_config_repo_archived(agent, true).await {
|
||||
Ok(true) => tracing::info!(hive, agent, "destroyed agent's config repo archived"),
|
||||
Ok(false) => tracing::debug!(
|
||||
hive,
|
||||
agent,
|
||||
"destroyed agent's config repo was already archived, or does not exist"
|
||||
),
|
||||
Err(e) => tracing::error!(
|
||||
hive,
|
||||
agent,
|
||||
error = %format!("{e:#}"),
|
||||
"archiving this agent's config repo FAILED; it was destroyed anyway, so the repo \
|
||||
still takes pushes. Declaring the agent destroyed again re-runs this."
|
||||
),
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue