1use std::time::{Duration, Instant};
4use tower_resilience_core::events::ResilienceEvent;
5
6#[derive(Debug, Clone)]
8pub enum BulkheadEvent {
9 CallPermitted {
11 pattern_name: String,
13 timestamp: Instant,
15 concurrent_calls: usize,
17 },
18 CallRejected {
20 pattern_name: String,
22 timestamp: Instant,
24 max_concurrent_calls: usize,
26 },
27 CallFinished {
29 pattern_name: String,
31 timestamp: Instant,
33 duration: Duration,
35 },
36 CallFailed {
38 pattern_name: String,
40 timestamp: Instant,
42 duration: Duration,
44 },
45}
46
47impl ResilienceEvent for BulkheadEvent {
48 fn event_type(&self) -> &'static str {
49 match self {
50 BulkheadEvent::CallPermitted { .. } => "call_permitted",
51 BulkheadEvent::CallRejected { .. } => "call_rejected",
52 BulkheadEvent::CallFinished { .. } => "call_finished",
53 BulkheadEvent::CallFailed { .. } => "call_failed",
54 }
55 }
56
57 fn timestamp(&self) -> Instant {
58 match self {
59 BulkheadEvent::CallPermitted { timestamp, .. }
60 | BulkheadEvent::CallRejected { timestamp, .. }
61 | BulkheadEvent::CallFinished { timestamp, .. }
62 | BulkheadEvent::CallFailed { timestamp, .. } => *timestamp,
63 }
64 }
65
66 fn pattern_name(&self) -> &str {
67 match self {
68 BulkheadEvent::CallPermitted { pattern_name, .. }
69 | BulkheadEvent::CallRejected { pattern_name, .. }
70 | BulkheadEvent::CallFinished { pattern_name, .. }
71 | BulkheadEvent::CallFailed { pattern_name, .. } => pattern_name,
72 }
73 }
74}