Skip to content

Commit a2b1203

Browse files
committed
docs(proxy): fix stale API references in README and mdBook
- with_round_robin(Default::default()) → with_round_robin(storage, config) (constructor takes two args: Arc<dyn ProxyStoragePort> + ProxyConfig) - start_health_checker(token) → let (cancel, _task) = manager.start() (start() returns the CancellationToken rather than accepting one) - ProxyManager::with_strategy(...) → builder pattern (no with_strategy method; use builder().storage().strategy().config().build()) - RotationStrategy impl: fn select → async fn select, Option → ProxyResult - Remove stale tokio_util::sync::CancellationToken imports from book examples - Add missing Arc/MemoryProxyStore imports to README code blocks
1 parent 4924b6f commit a2b1203

File tree

6 files changed

+43
-38
lines changed

6 files changed

+43
-38
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

book/src/proxy/health-circuit-breaker.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ slow or timing-out proxy does not delay checks for healthy ones.
1717

1818
```rust,no_run
1919
use std::sync::Arc;
20-
use tokio_util::sync::CancellationToken;
2120
use stygian_proxy::{MemoryProxyStore, ProxyConfig, ProxyManager};
2221
2322
let storage = Arc::new(MemoryProxyStore::default());
@@ -31,11 +30,10 @@ let manager = Arc::new(
3130
ProxyManager::with_round_robin(storage, config)?
3231
);
3332
34-
let token = CancellationToken::new();
35-
manager.start_health_checker(token.clone());
33+
let (cancel, _task) = manager.start();
3634
3735
// When shutting down:
38-
token.cancel();
36+
cancel.cancel();
3937
```
4038

4139
### On-demand check

book/src/proxy/overview.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ Build a pool and make a request:
3535

3636
```rust,no_run
3737
use std::sync::Arc;
38-
use tokio_util::sync::CancellationToken;
3938
use stygian_proxy::{MemoryProxyStore, ProxyConfig, ProxyManager};
4039
use stygian_proxy::types::{Proxy, ProxyType};
4140
@@ -57,8 +56,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
5756
}).await?;
5857
5958
// Start background health checks
60-
let token = CancellationToken::new();
61-
manager.start_health_checker(token.clone());
59+
let (cancel, _task) = manager.start();
6260
6361
// Acquire a proxy for a request
6462
let handle = manager.acquire_proxy().await?;
@@ -67,7 +65,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
6765
// Signal success — omitting this counts as a failure toward the circuit breaker
6866
handle.mark_success();
6967
70-
token.cancel(); // stop health checker
68+
cancel.cancel(); // stop health checker
7169
Ok(())
7270
}
7371
```

book/src/proxy/strategies.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ use stygian_proxy::{MemoryProxyStore, ProxyConfig, ProxyManager};
4747
use stygian_proxy::strategy::RandomStrategy;
4848
4949
let storage = Arc::new(MemoryProxyStore::default());
50-
let manager = ProxyManager::with_strategy(
51-
storage,
52-
ProxyConfig::default(),
53-
Arc::new(RandomStrategy),
54-
).unwrap();
50+
let manager = ProxyManager::builder()
51+
.storage(storage)
52+
.strategy(Arc::new(RandomStrategy))
53+
.config(ProxyConfig::default())
54+
.build()
55+
.unwrap();
5556
```
5657

5758
---
@@ -88,11 +89,12 @@ use stygian_proxy::{MemoryProxyStore, ProxyConfig, ProxyManager};
8889
use stygian_proxy::strategy::LeastUsedStrategy;
8990
9091
let storage = Arc::new(MemoryProxyStore::default());
91-
let manager = ProxyManager::with_strategy(
92-
storage,
93-
ProxyConfig::default(),
94-
Arc::new(LeastUsedStrategy),
95-
).unwrap();
92+
let manager = ProxyManager::builder()
93+
.storage(storage)
94+
.strategy(Arc::new(LeastUsedStrategy))
95+
.config(ProxyConfig::default())
96+
.build()
97+
.unwrap();
9698
```
9799

98100
---
@@ -128,7 +130,7 @@ impl RotationStrategy for BestSuccessRateStrategy {
128130
}
129131
```
130132

131-
Pass it to `ProxyManager::with_strategy(storage, config, Arc::new(BestSuccessRateStrategy))`.
133+
Pass it to `ProxyManager::builder().storage(storage).strategy(Arc::new(BestSuccessRateStrategy)).config(config).build().unwrap()`.
132134

133135
---
134136

crates/stygian-proxy/README.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ stygian-proxy = { version = "0.1", features = ["browser"] }
4848
## Quick Start
4949

5050
```rust,no_run
51-
use stygian_proxy::{ProxyManager, Proxy, types::ProxyType};
51+
use stygian_proxy::{ProxyManager, MemoryProxyStore, Proxy, types::{ProxyType, ProxyConfig}};
52+
use std::sync::Arc;
5253
use std::time::Duration;
5354
5455
#[tokio::main]
5556
async fn main() -> Result<(), Box<dyn std::error::Error>> {
5657
// Build a pool with round-robin rotation
57-
let manager = ProxyManager::with_round_robin(Default::default())?;
58+
let manager = ProxyManager::with_round_robin(Arc::new(MemoryProxyStore::default()), ProxyConfig::default())?;
5859
5960
// Add proxies
6061
manager.add_proxy(Proxy {
@@ -105,17 +106,20 @@ Custom strategies implement `RotationStrategy`:
105106

106107
```rust,no_run
107108
use stygian_proxy::strategy::{RotationStrategy, ProxyCandidate};
109+
use stygian_proxy::error::ProxyResult;
110+
use async_trait::async_trait;
108111
109112
#[derive(Debug)]
110113
struct MyStrategy;
111114
115+
#[async_trait]
112116
impl RotationStrategy for MyStrategy {
113-
fn select<'a>(&self, candidates: &'a [ProxyCandidate]) -> Option<&'a ProxyCandidate> {
117+
async fn select<'a>(&self, candidates: &'a [ProxyCandidate]) -> ProxyResult<&'a ProxyCandidate> {
114118
// pick the candidate with the best success rate
115119
candidates.iter().max_by(|a, b| {
116120
a.metrics.success_rate().partial_cmp(&b.metrics.success_rate())
117121
.unwrap_or(std::cmp::Ordering::Equal)
118-
})
122+
}).ok_or(stygian_proxy::error::ProxyError::AllProxiesUnhealthy)
119123
}
120124
}
121125
```
@@ -127,7 +131,8 @@ impl RotationStrategy for MyStrategy {
127131
Each proxy has its own `CircuitBreaker`. After `circuit_open_threshold` consecutive failures the breaker opens, and the proxy is excluded from rotation for `circuit_half_open_after`. After that window the proxy is tried once in HalfOpen state — a success closes it; another failure reopens it.
128132

129133
```rust,no_run
130-
use stygian_proxy::{ProxyManager, types::ProxyConfig};
134+
use stygian_proxy::{ProxyManager, MemoryProxyStore, types::ProxyConfig};
135+
use std::sync::Arc;
131136
use std::time::Duration;
132137
133138
let config = ProxyConfig {
@@ -138,7 +143,7 @@ let config = ProxyConfig {
138143
..Default::default()
139144
};
140145
141-
let manager = ProxyManager::with_round_robin(config)?;
146+
let manager = ProxyManager::with_round_robin(Arc::new(MemoryProxyStore::default()), config)?;
142147
```
143148

144149
If a `ProxyHandle` is dropped without calling `mark_success()`, the circuit breaker records a failure automatically.
@@ -150,7 +155,8 @@ If a `ProxyHandle` is dropped without calling `mark_success()`, the circuit brea
150155
`ProxyManager::start()` spawns a background task that probes each proxy on a configurable interval and updates per-proxy health scores:
151156

152157
```rust,no_run
153-
use stygian_proxy::{ProxyManager, types::ProxyConfig};
158+
use stygian_proxy::{ProxyManager, MemoryProxyStore, types::ProxyConfig};
159+
use std::sync::Arc;
154160
use std::time::Duration;
155161
156162
let config = ProxyConfig {
@@ -159,7 +165,7 @@ let config = ProxyConfig {
159165
..Default::default()
160166
};
161167
162-
let manager = ProxyManager::with_round_robin(config)?;
168+
let manager = ProxyManager::with_round_robin(Arc::new(MemoryProxyStore::default()), config)?;
163169
let (cancel_token, health_task) = manager.start();
164170
165171
// Graceful shutdown
@@ -178,9 +184,11 @@ stygian-graph = "0.1"
178184
```
179185

180186
```rust,no_run
181-
use stygian_proxy::{ProxyManager, graph::ProxyManagerPort};
187+
use stygian_proxy::{ProxyManager, MemoryProxyStore, graph::ProxyManagerPort};
188+
use stygian_proxy::types::ProxyConfig;
189+
use std::sync::Arc;
182190
183-
let manager = ProxyManager::with_round_robin(Default::default())?;
191+
let manager = ProxyManager::with_round_robin(Arc::new(MemoryProxyStore::default()), ProxyConfig::default())?;
184192
// Pass as Arc<dyn ProxyManagerPort> to RestApiAdapter or HttpAdapter
185193
```
186194

@@ -196,10 +204,12 @@ stygian-browser = "0.1"
196204
```
197205

198206
```rust,no_run
199-
use stygian_proxy::{ProxyManager, browser::ProxyManagerBridge};
207+
use stygian_proxy::{ProxyManager, MemoryProxyStore, browser::ProxyManagerBridge};
208+
use stygian_proxy::types::ProxyConfig;
200209
use stygian_browser::BrowserConfig;
210+
use std::sync::Arc;
201211
202-
let manager = std::sync::Arc::new(ProxyManager::with_round_robin(Default::default())?);
212+
let manager = Arc::new(ProxyManager::with_round_robin(Arc::new(MemoryProxyStore::default()), ProxyConfig::default())?);
203213
let bridge = ProxyManagerBridge::new(manager);
204214
// bridge.next_proxy_url().await? → inject into BrowserConfig::proxy
205215
```

crates/stygian-proxy/src/manager.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,7 @@ impl ProxyManager {
282282
// add_proxy() holds the circuit_breakers write lock for the full duration
283283
// of its storage write, so every proxy visible in candidates is guaranteed
284284
// to have a CB entry by the time we reach here.
285-
let cb = cb_map
286-
.get(&id)
287-
.cloned()
288-
.ok_or(ProxyError::PoolExhausted)?;
285+
let cb = cb_map.get(&id).cloned().ok_or(ProxyError::PoolExhausted)?;
289286

290287
let url = with_metrics
291288
.iter()

0 commit comments

Comments
 (0)