reactive_backoff_ms

Function reactive_backoff_ms 

Source
pub fn reactive_backoff_ms(
    config: &CostThrottleConfig,
    body: &Value,
    attempt: u32,
) -> u64
Expand description

Compute the reactive back-off delay from a throttle response body.

Use this when extensions.cost.throttleStatus signals THROTTLED rather than projecting from the LiveBudget.

deficit = max_available − currently_available
base_ms = deficit / restore_rate * 1100
ms      = (base_ms * 1.5^attempt).clamp(500, max_delay_ms)

§Example

use serde_json::json;
use stygian_graph::adapters::graphql_throttle::{CostThrottleConfig, reactive_backoff_ms};

let config = CostThrottleConfig::default();
let body = json!({ "extensions": { "cost": { "throttleStatus": {
    "maximumAvailable": 10000.0,
    "currentlyAvailable": 0.0,
    "restoreRate": 500.0,
}}}});
let ms = reactive_backoff_ms(&config, &body, 0);
assert!(ms >= 500);