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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use std::env;
mod error;
pub mod circular_queue;
pub mod insert_command;
pub mod cxn;
pub mod pool;
pub use self::error::TectonicError;
pub use self::cxn::Cxn;
pub use self::pool::CxnPool;
pub use self::insert_command::InsertCommand;
fn key_or_default(key: &str, default: &str) -> String {
match env::var(key) {
Ok(val) => val,
Err(_) => default.into(),
}
}
fn get_tectonic_conf_from_env() -> (String, String, usize) {
let tectonic_hostname: String = key_or_default("TECTONICDB_HOSTNAME", "localhost");
let tectonic_port: String = key_or_default("TECTONICDB_PORT", "9001");
let q_capacity: usize = key_or_default("QUEUE_CAPACITY", "70000000")
.parse().unwrap();
(tectonic_hostname, tectonic_port, q_capacity)
}
pub fn get_cxn() -> Cxn {
let (tectonic_hostname, tectonic_port, _capacity) = get_tectonic_conf_from_env();
match Cxn::new(&tectonic_hostname, &tectonic_port) {
Ok(cxn) => cxn,
Err(TectonicError::ConnectionError) => {
panic!("DB cannot be connected!");
},
_ => unreachable!(),
}
}
pub fn get_cxn_pool() -> CxnPool {
let (tectonic_hostname, tectonic_port, capacity) = get_tectonic_conf_from_env();
match CxnPool::new(1, &tectonic_hostname, &tectonic_port, capacity) {
Ok(pool) => pool,
Err(TectonicError::ConnectionError) => {
panic!("Connection Pool cannot be established!");
},
_ => unreachable!(),
}
}