fix(daemon): extract hardcoded values in autospawn registration #254
1 changed files with 6 additions and 12 deletions
|
|
@ -630,6 +630,9 @@ pub async fn autospawn_agent_if_configured(state: &SharedState) {
|
|||
if resp.ok {
|
||||
info!("autospawn: agent spawned");
|
||||
|
||||
// Extract hostname once — used by both agent registration and hw profile.
|
||||
let hostname = std::env::var("HOSTNAME").unwrap_or_else(|_| "unknown".to_string());
|
||||
|
||||
// Resolve agent_id from the spawn response for both registration and RPC.
|
||||
let agent_id = resp
|
||||
.data
|
||||
|
|
@ -642,14 +645,10 @@ pub async fn autospawn_agent_if_configured(state: &SharedState) {
|
|||
// can route queued tasks to it. Without this, tasks stay stuck in
|
||||
// "queued" — the scheduler only assigns work to registered agents.
|
||||
if let Some(ref aid) = agent_id {
|
||||
let hostname = std::env::var("HOSTNAME").unwrap_or_else(|_| "unknown".to_string());
|
||||
let caps = serde_json::json!(["shell", "freebsd", "code"]);
|
||||
match state.store.try_lock() {
|
||||
Ok(store) => {
|
||||
if let Err(e) = store.register_agent(
|
||||
aid,
|
||||
serde_json::json!(["shell", "freebsd", "code"]),
|
||||
Some(&hostname),
|
||||
) {
|
||||
if let Err(e) = store.register_agent(aid, caps.clone(), Some(&hostname)) {
|
||||
warn!(agent_id = %aid, error = %e, "autospawn: failed to register agent in store");
|
||||
} else {
|
||||
info!(agent_id = %aid, hostname = %hostname, "autospawn: agent registered for task work");
|
||||
|
|
@ -659,11 +658,7 @@ pub async fn autospawn_agent_if_configured(state: &SharedState) {
|
|||
warn!("autospawn: store locked; agent registration deferred");
|
||||
}
|
||||
Err(std::sync::TryLockError::Poisoned(e)) => {
|
||||
if let Err(e) = e.into_inner().register_agent(
|
||||
aid,
|
||||
serde_json::json!(["shell", "freebsd", "code"]),
|
||||
Some(&hostname),
|
||||
) {
|
||||
if let Err(e) = e.into_inner().register_agent(aid, caps, Some(&hostname)) {
|
||||
warn!(agent_id = %aid, error = %e, "autospawn: failed to register agent (poisoned store)");
|
||||
}
|
||||
}
|
||||
|
|
@ -692,7 +687,6 @@ pub async fn autospawn_agent_if_configured(state: &SharedState) {
|
|||
|
||||
// Register hardware profile with mother if configured (best-effort).
|
||||
if let Some(hw_json) = hw_profile_for_mother {
|
||||
let hostname = std::env::var("HOSTNAME").unwrap_or_else(|_| "unknown".to_string());
|
||||
// Spawn a detached tokio task so SSH retries don't block the daemon.
|
||||
let hw_json = hw_json.clone();
|
||||
tokio::spawn(async move {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue