orch-cli 0.113.0

Orch, the agent orchestration engine: runs coding agents on tasks and cron jobs
Documentation
//! This node's entry in the cluster's node registry, written on start, on config reload and on a heartbeat

use std::collections::HashSet;
use std::sync::Arc;

use chrono::Utc;
use tokio::sync::RwLock;

use crate::config;
use crate::engine::router::Router;
use crate::store::TaskStore;
use crate::store::cluster::registry::{self, Entry};

/// Write the entry in the background, so a write that waits for a leader never stalls the tick
pub(crate) async fn publish(
    store: &Arc<TaskStore>,
    repos: &HashSet<String>,
    router: &Arc<RwLock<Router>>,
    max_parallel: usize,
) {
    let Some(node) = store.node() else {
        return;
    };
    let mut projects: Vec<String> = repos.iter().cloned().collect();
    projects.sort();
    let entry = Entry {
        node: node.name().to_string(),
        projects,
        agents: router.read().await.available_agents.clone(),
        max_parallel,
        version: node.version(),
        witness: config::get("cluster.witness").is_ok_and(|w| w == "true"),
        seen: Utc::now().to_rfc3339(),
    };
    let store = Arc::clone(store);
    tokio::spawn(async move {
        if let Err(e) = registry::write(&store, &entry).await {
            tracing::warn!(err = %e, "failed to write this node's registry entry");
        }
    });
}