postrust_proxy/config/
reload.rs1use crate::config::ProxyConfig;
4use std::sync::Arc;
5use tokio::sync::RwLock;
6
7#[derive(Debug, Clone)]
9pub enum ConfigChangeEvent {
10 FileChanged,
12 RouteChanged { id: uuid::Uuid },
14 UpstreamChanged { id: uuid::Uuid },
16 BackendChanged { id: uuid::Uuid },
18 FullReload,
20}
21
22pub struct ConfigReloader {
24 config: Arc<RwLock<ProxyConfig>>,
26 change_tx: tokio::sync::mpsc::Sender<ConfigChangeEvent>,
28 change_rx: tokio::sync::Mutex<tokio::sync::mpsc::Receiver<ConfigChangeEvent>>,
30}
31
32impl ConfigReloader {
33 pub fn new(config: Arc<RwLock<ProxyConfig>>) -> Self {
35 let (change_tx, change_rx) = tokio::sync::mpsc::channel(100);
36
37 Self {
38 config,
39 change_tx,
40 change_rx: tokio::sync::Mutex::new(change_rx),
41 }
42 }
43
44 pub async fn request_reload(&self) {
46 let _ = self.change_tx.send(ConfigChangeEvent::FullReload).await;
47 }
48
49 pub fn change_sender(&self) -> tokio::sync::mpsc::Sender<ConfigChangeEvent> {
51 self.change_tx.clone()
52 }
53}