cat_gateway/settings/
event_db.rs

1//! Command line and environment variable settings for the service
2
3use super::str_env_var::StringEnvVar;
4
5/// Sets the maximum number of connections managed by the pool.
6/// Defaults to 100.
7const EVENT_DB_MAX_CONNECTIONS: u32 = 100;
8
9/// Sets the maximum lifetime of connections in the pool.
10/// Defaults to 30 minutes.
11const EVENT_DB_MAX_LIFETIME: u32 = 30;
12
13/// Sets the minimum idle connection count maintained by the pool.
14/// Defaults to 0.
15const EVENT_DB_MIN_IDLE: u32 = 0;
16
17/// Sets the connection timeout used by the pool.
18/// Defaults to 300 seconds.
19const EVENT_DB_CONN_TIMEOUT: u32 = 300;
20
21/// Default Event DB URL.
22const EVENT_DB_URL_DEFAULT: &str =
23    "postgresql://postgres:postgres@localhost/catalyst_events?sslmode=disable";
24
25/// Configuration for event db.
26#[derive(Clone)]
27pub(crate) struct EnvVars {
28    /// The Address of the Event DB.
29    pub(crate) url: StringEnvVar,
30
31    /// The `UserName` to use for the Event DB.
32    pub(crate) username: Option<StringEnvVar>,
33
34    /// The Address of the Event DB.
35    pub(crate) password: Option<StringEnvVar>,
36
37    /// Sets the maximum number of connections managed by the pool.
38    /// Defaults to 10.
39    pub(crate) max_connections: u32,
40
41    /// Sets the maximum lifetime of connections in the pool.
42    /// Defaults to 30 minutes.
43    pub(crate) max_lifetime: u32,
44
45    /// Sets the minimum idle connection count maintained by the pool.
46    /// Defaults to None.
47    pub(crate) min_idle: u32,
48
49    /// Sets the connection timeout used by the pool.
50    /// Defaults to 30 seconds.
51    pub(crate) connection_timeout: u32,
52}
53
54impl EnvVars {
55    /// Create a config for event db.
56    pub(super) fn new() -> Self {
57        Self {
58            url: StringEnvVar::new("EVENT_DB_URL", (EVENT_DB_URL_DEFAULT, true).into()),
59            username: StringEnvVar::new_optional("EVENT_DB_USERNAME", false),
60            password: StringEnvVar::new_optional("EVENT_DB_PASSWORD", true),
61            max_connections: StringEnvVar::new_as_int(
62                "EVENT_DB_MAX_CONNECTIONS",
63                EVENT_DB_MAX_CONNECTIONS,
64                0,
65                u32::MAX,
66            ),
67            max_lifetime: StringEnvVar::new_as_int(
68                "EVENT_DB_MAX_LIFETIME",
69                EVENT_DB_MAX_LIFETIME,
70                0,
71                u32::MAX,
72            ),
73            min_idle: StringEnvVar::new_as_int("EVENT_DB_MIN_IDLE", EVENT_DB_MIN_IDLE, 0, u32::MAX),
74            connection_timeout: StringEnvVar::new_as_int(
75                "EVENT_DB_CONN_TIMEOUT",
76                EVENT_DB_CONN_TIMEOUT,
77                0,
78                u32::MAX,
79            ),
80        }
81    }
82}