use std::{num::NonZeroU32, time::Duration};
#[derive(Debug, Clone)]
pub struct MetaForgeConfig {
pub base_url: String,
pub rate: RateConfig,
pub retries: RetryConfig,
}
impl Default for MetaForgeConfig {
fn default() -> Self {
Self {
base_url: "https://metaforge.app/api".to_string(),
rate: RateConfig::polite_defaults(),
retries: RetryConfig::default(),
}
}
}
#[derive(Debug, Clone)]
pub struct RateConfig {
pub rps: NonZeroU32,
pub burst: NonZeroU32,
pub max_inflight: NonZeroU32,
}
impl RateConfig {
pub fn polite_defaults() -> Self {
Self {
rps: NonZeroU32::new(5).expect("nonzero"),
burst: NonZeroU32::new(10).expect("nonzero"),
max_inflight: NonZeroU32::new(8).expect("nonzero"),
}
}
pub fn very_polite() -> Self {
Self {
rps: NonZeroU32::new(2).expect("nonzero"),
burst: NonZeroU32::new(4).expect("nonzero"),
max_inflight: NonZeroU32::new(4).expect("nonzero"),
}
}
}
#[derive(Debug, Clone)]
pub struct RetryConfig {
pub max_attempts: u32,
pub base_backoff: Duration,
pub max_backoff: Duration,
}
impl Default for RetryConfig {
fn default() -> Self {
Self {
max_attempts: 5,
base_backoff: Duration::from_millis(200),
max_backoff: Duration::from_secs(5),
}
}
}