Review fixes for the persistent logs: - each service writes its own folder (the old-file cleanup matches by prefix, so 'worker' deleted the 'worker-ai' files); - at most LOG_MAX_DAY_MB (50) a day, and at least 2 days kept; - written by a background thread, not on the async workers; - e-mail addresses and tokens in request paths are masked; - a failing health check is logged again, a passing one is not; - one-off commands (compare-models) log to the console only. On a stop the worker takes nothing new and lets running work finish (SHUTDOWN_DRAIN_SECS, worker 40 s, worker-ai 270 s, with matching stop grace periods), so a deploy no longer cuts an analysis off, wastes its model call and delays it by the 15-minute stuck-job requeue. The CI cleanup caps the build cache at 10 GB: by age it had grown to 33 GB on the runner and filled its disk. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
65 lines
2.2 KiB
Rust
65 lines
2.2 KiB
Rust
//! Natal chart and synastry HTTP API.
|
|
//!
|
|
//! Configuration (environment):
|
|
//! * `ASTRO_DATA_DIR` directory with `ephe/`, `zoneinfo/`, `geonames/` (default `./data`)
|
|
//! * `BIND_ADDR` listen address (default `0.0.0.0:8080`)
|
|
//! * `CORS_ALLOWED_ORIGINS` `*` (default) or a comma-separated list of origins
|
|
//! * `LOG_FORMAT` `text` (default) or `json`; `RUST_LOG` sets the level
|
|
//!
|
|
//! `horoscope-api healthcheck` performs a local health check (for Docker).
|
|
|
|
mod error;
|
|
mod forecast;
|
|
mod natal;
|
|
mod routes;
|
|
mod synastry;
|
|
#[cfg(test)]
|
|
mod tests;
|
|
|
|
use std::path::PathBuf;
|
|
use std::sync::Arc;
|
|
use std::time::Instant;
|
|
|
|
use anyhow::Context;
|
|
use astro_engine::Ephemeris;
|
|
use astro_engine::swiss::SwissEphemeris;
|
|
use geo_tz::Atlas;
|
|
|
|
pub struct AppState {
|
|
pub engine: Arc<dyn Ephemeris>,
|
|
pub atlas: Atlas,
|
|
}
|
|
|
|
const DEFAULT_BIND_ADDR: &str = "0.0.0.0:8080";
|
|
|
|
fn load_state() -> anyhow::Result<AppState> {
|
|
let data_dir = PathBuf::from(std::env::var("ASTRO_DATA_DIR").unwrap_or_else(|_| "data".into()));
|
|
let started = Instant::now();
|
|
let engine = SwissEphemeris::new(data_dir.join("ephe"))
|
|
.with_context(|| format!("loading ephemeris from {}", data_dir.join("ephe").display()))?;
|
|
let atlas = Atlas::load(&data_dir).with_context(|| format!("loading data from {}", data_dir.display()))?;
|
|
tracing::info!(
|
|
places = atlas.places.len(),
|
|
tzdb = %atlas.zones.version,
|
|
ephemeris = %engine.info().version,
|
|
elapsed_ms = started.elapsed().as_millis() as u64,
|
|
"data loaded"
|
|
);
|
|
Ok(AppState { engine: Arc::new(engine), atlas })
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> anyhow::Result<()> {
|
|
let addr = service_kit::bind_addr(DEFAULT_BIND_ADDR)?;
|
|
if std::env::args().nth(1).as_deref() == Some("healthcheck") {
|
|
return service_kit::healthcheck(addr);
|
|
}
|
|
let _log = service_kit::init_logging("horoscope-api");
|
|
let state = Arc::new(tokio::task::spawn_blocking(load_state).await??);
|
|
let app = routes::router(state);
|
|
let listener = tokio::net::TcpListener::bind(addr).await.with_context(|| format!("binding {addr}"))?;
|
|
tracing::info!(%addr, "listening");
|
|
axum::serve(listener, app).with_graceful_shutdown(service_kit::shutdown_signal()).await?;
|
|
Ok(())
|
|
}
|