@@ -18,6 +18,11 @@ use crates_io_env_vars::{required_var, var, var_parsed};
18
18
use secrecy:: SecretString ;
19
19
use std:: time:: Duration ;
20
20
21
+ const DEFAULT_POOL_SIZE : usize = 3 ;
22
+ const DEFAULT_HELPER_THREADS : usize = 3 ;
23
+ const DEFAULT_TCP_TIMEOUT : Duration = Duration :: from_secs ( 15 ) ;
24
+ const DEFAULT_CONNECTION_TIMEOUT : Duration = Duration :: from_secs ( 30 ) ;
25
+
21
26
pub struct DatabasePools {
22
27
/// Settings for the primary database. This is usually writeable, but will be read-only in
23
28
/// some configurations.
@@ -58,8 +63,6 @@ impl DatabasePools {
58
63
}
59
64
60
65
impl DatabasePools {
61
- const DEFAULT_POOL_SIZE : usize = 3 ;
62
-
63
66
/// Load settings for one or more database pools from the environment
64
67
///
65
68
/// # Panics
@@ -71,24 +74,26 @@ impl DatabasePools {
71
74
let read_only_mode = var ( "READ_ONLY_MODE" ) ?. is_some ( ) ;
72
75
73
76
let primary_async_pool_size =
74
- var_parsed ( "DB_PRIMARY_ASYNC_POOL_SIZE" ) ?. unwrap_or ( Self :: DEFAULT_POOL_SIZE ) ;
77
+ var_parsed ( "DB_PRIMARY_ASYNC_POOL_SIZE" ) ?. unwrap_or ( DEFAULT_POOL_SIZE ) ;
75
78
let replica_async_pool_size =
76
- var_parsed ( "DB_REPLICA_ASYNC_POOL_SIZE" ) ?. unwrap_or ( Self :: DEFAULT_POOL_SIZE ) ;
79
+ var_parsed ( "DB_REPLICA_ASYNC_POOL_SIZE" ) ?. unwrap_or ( DEFAULT_POOL_SIZE ) ;
77
80
78
81
let primary_min_idle = var_parsed ( "DB_PRIMARY_MIN_IDLE" ) ?;
79
82
let replica_min_idle = var_parsed ( "DB_REPLICA_MIN_IDLE" ) ?;
80
83
81
- let tcp_timeout = var_parsed ( "DB_TCP_TIMEOUT_MS" ) ?. unwrap_or ( 15 * 1000 ) ;
82
- let tcp_timeout = Duration :: from_millis ( tcp_timeout) ;
84
+ let tcp_timeout = var_parsed ( "DB_TCP_TIMEOUT_MS" ) ?
85
+ . map ( Duration :: from_millis)
86
+ . unwrap_or ( DEFAULT_TCP_TIMEOUT ) ;
83
87
84
- let connection_timeout = var_parsed ( "DB_TIMEOUT" ) ?. unwrap_or ( 30 ) ;
85
- let connection_timeout = Duration :: from_secs ( connection_timeout) ;
88
+ let connection_timeout = var_parsed ( "DB_TIMEOUT" ) ?
89
+ . map ( Duration :: from_millis)
90
+ . unwrap_or ( DEFAULT_CONNECTION_TIMEOUT ) ;
86
91
87
92
// `DB_TIMEOUT` currently configures both the connection timeout and
88
93
// the statement timeout, so we can copy the parsed connection timeout.
89
94
let statement_timeout = connection_timeout;
90
95
91
- let helper_threads = var_parsed ( "DB_HELPER_THREADS" ) ?. unwrap_or ( 3 ) ;
96
+ let helper_threads = var_parsed ( "DB_HELPER_THREADS" ) ?. unwrap_or ( DEFAULT_HELPER_THREADS ) ;
92
97
93
98
let enforce_tls = base. env == Env :: Production ;
94
99
0 commit comments