pub struct ProxyManager { /* private fields */ }Expand description
Unified proxy pool orchestrator.
Manage proxies via add_proxy and
remove_proxy, acquire one via
acquire_proxy, and start background
health checking with start.
§Quick start
use std::sync::Arc;
use stygian_proxy::{ProxyManager, ProxyConfig, Proxy, ProxyType};
use stygian_proxy::storage::MemoryProxyStore;
let storage = Arc::new(MemoryProxyStore::default());
let mgr = ProxyManager::with_round_robin(storage, ProxyConfig::default())?;
let (token, _handle) = mgr.start();
let proxy = mgr.add_proxy(Proxy {
url: "http://proxy.example.com:8080".into(),
proxy_type: ProxyType::Http,
username: None,
password: None,
weight: 1,
tags: vec![],
}).await?;
let handle = mgr.acquire_proxy().await?;
handle.mark_success();
token.cancel();Implementations§
Source§impl ProxyManager
impl ProxyManager
Sourcepub fn builder() -> ProxyManagerBuilder
pub fn builder() -> ProxyManagerBuilder
Start a ProxyManagerBuilder.
Sourcepub fn with_round_robin(
storage: Arc<dyn ProxyStoragePort>,
config: ProxyConfig,
) -> ProxyResult<Self>
pub fn with_round_robin( storage: Arc<dyn ProxyStoragePort>, config: ProxyConfig, ) -> ProxyResult<Self>
Convenience: round-robin rotation (default).
Sourcepub fn with_random(
storage: Arc<dyn ProxyStoragePort>,
config: ProxyConfig,
) -> ProxyResult<Self>
pub fn with_random( storage: Arc<dyn ProxyStoragePort>, config: ProxyConfig, ) -> ProxyResult<Self>
Convenience: random rotation.
Sourcepub fn with_weighted(
storage: Arc<dyn ProxyStoragePort>,
config: ProxyConfig,
) -> ProxyResult<Self>
pub fn with_weighted( storage: Arc<dyn ProxyStoragePort>, config: ProxyConfig, ) -> ProxyResult<Self>
Convenience: weighted rotation.
Sourcepub fn with_least_used(
storage: Arc<dyn ProxyStoragePort>,
config: ProxyConfig,
) -> ProxyResult<Self>
pub fn with_least_used( storage: Arc<dyn ProxyStoragePort>, config: ProxyConfig, ) -> ProxyResult<Self>
Convenience: least-used rotation.
Sourcepub async fn add_proxy(&self, proxy: Proxy) -> ProxyResult<Uuid>
pub async fn add_proxy(&self, proxy: Proxy) -> ProxyResult<Uuid>
Add a proxy and register a circuit breaker for it. Returns the new ID.
The circuit_breakers write lock is held for the duration of the storage
write. This is intentional: acquire_proxy holds
a read lock on the same map while it inspects candidates, so it cannot
proceed past that point until both the storage record and its CB entry
exist. Without this ordering a concurrent acquire_proxy could select
the new proxy before its CB was registered, breaking failure accounting.
Sourcepub async fn remove_proxy(&self, id: Uuid) -> ProxyResult<()>
pub async fn remove_proxy(&self, id: Uuid) -> ProxyResult<()>
Remove a proxy from the pool and drop its circuit breaker.
Sourcepub fn start(&self) -> (CancellationToken, JoinHandle<()>)
pub fn start(&self) -> (CancellationToken, JoinHandle<()>)
Spawn the background health-check task.
Returns a (CancellationToken, JoinHandle) pair. Cancel the token to
trigger a graceful shutdown; await the handle to ensure it finishes.
Sourcepub async fn acquire_proxy(&self) -> ProxyResult<ProxyHandle>
pub async fn acquire_proxy(&self) -> ProxyResult<ProxyHandle>
Acquire a proxy from the pool.
Builds ProxyCandidate entries from current storage, consulting the
health map and each proxy’s circuit breaker to set the healthy flag.
Delegates selection to the configured [RotationStrategy].
Sourcepub async fn pool_stats(&self) -> ProxyResult<PoolStats>
pub async fn pool_stats(&self) -> ProxyResult<PoolStats>
Return a health snapshot of the pool.