Skip to main content

orch/cli/
webhook.rs

1//! `orch webhook` subcommands.
2
3use crate::webhook_status::WebhookStatus;
4
5/// Print the last-known webhook health state from `~/.orch/webhook_status.json`.
6pub fn status() -> anyhow::Result<()> {
7    match WebhookStatus::load() {
8        None => {
9            println!("Webhook status: unavailable");
10            println!("  (service not running or webhooks have never been configured)");
11        }
12        Some(s) => {
13            let health_str = if s.healthy { "healthy" } else { "unhealthy" };
14            let fallback_str = if s.fallback_mode {
15                "yes (polling)"
16            } else {
17                "no"
18            };
19            let port_str = s.port.map_or_else(|| "—".to_string(), |p| p.to_string());
20            let last_check = s
21                .last_check_utc
22                .map_or_else(|| "never".to_string(), |t| t.to_rfc3339());
23            let failure = s.last_failure_reason.as_deref().unwrap_or("none");
24
25            println!("Webhook status:");
26            println!("  Configured:       {}", s.configured);
27            println!("  Port:             {port_str}");
28            println!("  Health:           {health_str}");
29            println!("  Fallback mode:    {fallback_str}");
30            println!("  Last check (UTC): {last_check}");
31            println!("  Startup attempts: {}", s.startup_attempts);
32            println!("  Last failure:     {failure}");
33        }
34    }
35    Ok(())
36}