use std::time::{Duration, Instant};
use tower_resilience_core::events::ResilienceEvent;
#[derive(Debug, Clone)]
pub enum BulkheadEvent {
CallPermitted {
pattern_name: String,
timestamp: Instant,
concurrent_calls: usize,
},
CallRejected {
pattern_name: String,
timestamp: Instant,
max_concurrent_calls: usize,
},
CallFinished {
pattern_name: String,
timestamp: Instant,
duration: Duration,
},
CallFailed {
pattern_name: String,
timestamp: Instant,
duration: Duration,
},
}
impl ResilienceEvent for BulkheadEvent {
fn event_type(&self) -> &'static str {
match self {
BulkheadEvent::CallPermitted { .. } => "call_permitted",
BulkheadEvent::CallRejected { .. } => "call_rejected",
BulkheadEvent::CallFinished { .. } => "call_finished",
BulkheadEvent::CallFailed { .. } => "call_failed",
}
}
fn timestamp(&self) -> Instant {
match self {
BulkheadEvent::CallPermitted { timestamp, .. }
| BulkheadEvent::CallRejected { timestamp, .. }
| BulkheadEvent::CallFinished { timestamp, .. }
| BulkheadEvent::CallFailed { timestamp, .. } => *timestamp,
}
}
fn pattern_name(&self) -> &str {
match self {
BulkheadEvent::CallPermitted { pattern_name, .. }
| BulkheadEvent::CallRejected { pattern_name, .. }
| BulkheadEvent::CallFinished { pattern_name, .. }
| BulkheadEvent::CallFailed { pattern_name, .. } => pattern_name,
}
}
}