Skip to main content

weft_core/pipeline/
context.rs

1use std::time::Instant;
2
3/// Mutable context that flows through the entire pipeline.
4#[derive(Debug)]
5pub struct RequestContext {
6    pub request_id: String,
7    pub selected_provider: Option<String>,
8    pub selected_key_index: Option<usize>,
9    pub selected_key_value: Option<String>,
10    pub retry_count: u32,
11    pub start_time: Instant,
12}
13
14impl Default for RequestContext {
15    fn default() -> Self {
16        Self::new()
17    }
18}
19
20impl RequestContext {
21    pub fn new() -> Self {
22        Self {
23            request_id: uuid::Uuid::new_v4().to_string(),
24            selected_provider: None,
25            selected_key_index: None,
26            selected_key_value: None,
27            retry_count: 0,
28            start_time: Instant::now(),
29        }
30    }
31
32    pub fn elapsed_ms(&self) -> u64 {
33        self.start_time.elapsed().as_millis() as u64
34    }
35}