integrationos_domain/domain/configuration/
cache.rs

1use envconfig::Envconfig;
2use std::fmt::{Display, Formatter};
3
4#[derive(Envconfig, Debug, Clone)]
5pub struct CacheConfig {
6    #[envconfig(from = "REDIS_URL", default = "redis://127.0.0.1:6379")]
7    pub url: String,
8    #[envconfig(from = "REDIS_QUEUE_NAME", default = "events")]
9    pub queue_name: String,
10    #[envconfig(from = "REDIS_EVENT_THROUGHPUT_KEY", default = "event_throughput")]
11    pub event_throughput_key: String,
12    #[envconfig(from = "REDIS_API_THROUGHPUT_KEY", default = "api_throughput")]
13    pub api_throughput_key: String,
14    #[envconfig(from = "REDIS_POOL_SIZE", default = "10")]
15    pub pool_size: usize,
16    #[envconfig(env = "CACHE_WAIT_TIMEOUT_SECONDS", default = "30")]
17    pub wait_timeout: u64,
18    #[envconfig(env = "CACHE_CREATE_TIMEOUT_SECONDS", default = "30")]
19    pub create_timeout: u64,
20    #[envconfig(env = "CACHE_RECYCLE_TIMEOUT_SECONDS", default = "30")]
21    pub recycle_timeout: u64,
22}
23
24impl Default for CacheConfig {
25    fn default() -> Self {
26        Self {
27            url: "redis://localhost:6379".to_owned(),
28            queue_name: "events".to_owned(),
29            event_throughput_key: "event_throughput".to_owned(),
30            api_throughput_key: "api_throughput".to_owned(),
31            pool_size: 10,
32            wait_timeout: 30,
33            create_timeout: 30,
34            recycle_timeout: 30,
35        }
36    }
37}
38
39impl Display for CacheConfig {
40    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
41        writeln!(f, "REDIS_URL: {}", self.url)?;
42        writeln!(f, "REDIS_QUEUE_NAME: {}", self.queue_name)?;
43        writeln!(
44            f,
45            "REDIS_EVENT_THROUGHPUT_KEY: {}",
46            self.event_throughput_key
47        )?;
48        writeln!(f, "REDIS_API_THROUGHPUT_KEY: {}", self.api_throughput_key)?;
49        writeln!(f, "REDIS_POOL_SIZE: {}", self.pool_size)?;
50        writeln!(f, "CACHE_WAIT_TIMEOUT_SECONDS: {}", self.wait_timeout)?;
51        writeln!(f, "CACHE_CREATE_TIMEOUT_SECONDS: {}", self.create_timeout)?;
52        writeln!(f, "CACHE_RECYCLE_TIMEOUT_SECONDS: {}", self.recycle_timeout)
53    }
54}