-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathenv_config.rs
More file actions
41 lines (40 loc) · 1.61 KB
/
Copy pathenv_config.rs
File metadata and controls
41 lines (40 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#[derive(Debug, Clone)]
pub struct EnvConfig {
pub grpc_vfs_url: String,
pub grpc_vfs_connect_timeout_secs: u64,
pub local_cache_dir: Option<String>,
pub max_cache_bytes: Option<u64>,
/// Locally read values instead of going to the server. Risks stale data.
pub local_reads: bool,
/// Preload the cache on startup. Does not block reads. Will start from the DB head and download up to the max cache size.
pub preload_cache: bool,
pub preload_cache_concurrency: u32,
}
impl EnvConfig {
pub fn new() -> Self {
Self {
grpc_vfs_url: std::env::var("GRPC_VFS_URL")
.unwrap_or_else(|_| "http://localhost:50051".to_string()),
grpc_vfs_connect_timeout_secs: std::env::var("GRPC_VFS_CONNECT_TIMEOUT_SECS")
.unwrap_or_else(|_| "10".to_string())
.parse::<u64>()
.unwrap_or(10),
local_cache_dir: std::env::var("LOCAL_CACHE_DIR").ok(),
max_cache_bytes: std::env::var("MAX_CACHE_BYTES")
.ok()
.and_then(|s| s.parse::<u64>().ok()),
local_reads: std::env::var("LOCAL_READS")
.ok()
.and_then(|s| s.parse::<bool>().ok())
.unwrap_or(false),
preload_cache: std::env::var("PRELOAD_CACHE")
.ok()
.and_then(|s| s.parse::<bool>().ok())
.unwrap_or(false),
preload_cache_concurrency: std::env::var("PRELOAD_CACHE_CONCURRENCY")
.ok()
.and_then(|s| s.parse::<u32>().ok())
.unwrap_or(4),
}
}
}