@@ -4,9 +4,17 @@ use std::time::Duration;
4
4
5
5
use super :: str_env_var:: StringEnvVar ;
6
6
7
- /// Sets the maximum number of connections managed by the pool.
8
- /// Defaults to 100.
9
- const EVENT_DB_MAX_CONNECTIONS : u32 = 100 ;
7
+ /// Default the maximum number of connections managed by the pool.
8
+ const EVENT_DB_MAX_CONNECTIONS_DEFAULT : u32 = 100 ;
9
+
10
+ /// Default the timeout when creating a new connection.
11
+ const EVENT_DB_CONN_TIMEOUT_DEFAULT : Duration = Duration :: from_secs ( 5 ) ;
12
+
13
+ /// Default the timeout for waiting for a slot to become available.
14
+ const EVENT_DB_SLOT_WAIT_TIMEOUT_DEFAULT : Duration = Duration :: from_secs ( 5 ) ;
15
+
16
+ /// Default the timeout when for recycling a connection.
17
+ const EVENT_DB_CONN_RECYCLE_TIMEOUT_DEFAULT : Duration = Duration :: from_secs ( 5 ) ;
10
18
11
19
/// Default Event DB URL.
12
20
const EVENT_DB_URL_DEFAULT : & str =
@@ -29,13 +37,16 @@ pub(crate) struct EnvVars {
29
37
max_connections : u32 ,
30
38
31
39
/// Sets the timeout when creating a new connection.
32
- connection_creation_timeout : Option < Duration > ,
40
+ /// Defaults to 5 seconds.
41
+ connection_creation_timeout : Duration ,
33
42
34
43
/// Sets the timeout for waiting for a slot to become available.
35
- slot_wait_timeout : Option < Duration > ,
44
+ /// Defaults to 5 seconds.
45
+ slot_wait_timeout : Duration ,
36
46
37
47
/// Sets the timeout when for recycling a connection.
38
- connection_recycle_timeout : Option < Duration > ,
48
+ /// Defaults to 5 seconds.
49
+ connection_recycle_timeout : Duration ,
39
50
}
40
51
41
52
impl EnvVars {
@@ -47,16 +58,21 @@ impl EnvVars {
47
58
password : StringEnvVar :: new_optional ( "EVENT_DB_PASSWORD" , true ) ,
48
59
max_connections : StringEnvVar :: new_as_int (
49
60
"EVENT_DB_MAX_CONNECTIONS" ,
50
- EVENT_DB_MAX_CONNECTIONS ,
61
+ EVENT_DB_MAX_CONNECTIONS_DEFAULT ,
51
62
0 ,
52
63
u32:: MAX ,
53
64
) ,
54
- connection_creation_timeout : StringEnvVar :: new_as_duration_optional (
65
+ connection_creation_timeout : StringEnvVar :: new_as_duration (
55
66
"EVENT_DB_CONN_TIMEOUT" ,
67
+ EVENT_DB_CONN_TIMEOUT_DEFAULT ,
68
+ ) ,
69
+ slot_wait_timeout : StringEnvVar :: new_as_duration (
70
+ "EVENT_DB_SLOT_WAIT_TIMEOUT" ,
71
+ EVENT_DB_SLOT_WAIT_TIMEOUT_DEFAULT ,
56
72
) ,
57
- slot_wait_timeout : StringEnvVar :: new_as_duration_optional ( "EVENT_DB_SLOT_WAIT_TIMEOUT" ) ,
58
- connection_recycle_timeout : StringEnvVar :: new_as_duration_optional (
73
+ connection_recycle_timeout : StringEnvVar :: new_as_duration (
59
74
"EVENT_DB_CONN_RECYCLE_TIMEOUT" ,
75
+ EVENT_DB_CONN_RECYCLE_TIMEOUT_DEFAULT ,
60
76
) ,
61
77
}
62
78
}
@@ -82,17 +98,17 @@ impl EnvVars {
82
98
}
83
99
84
100
/// Returns Event DB `connection_creation_timeout` setting
85
- pub ( crate ) fn connection_creation_timeout ( & self ) -> Option < Duration > {
101
+ pub ( crate ) fn connection_creation_timeout ( & self ) -> Duration {
86
102
self . connection_creation_timeout
87
103
}
88
104
89
105
/// Returns Event DB `slot_wait_timeout` setting
90
- pub ( crate ) fn slot_wait_timeout ( & self ) -> Option < Duration > {
106
+ pub ( crate ) fn slot_wait_timeout ( & self ) -> Duration {
91
107
self . slot_wait_timeout
92
108
}
93
109
94
110
/// Returns Event DB `connection_recycle_timeout` setting
95
- pub ( crate ) fn connection_recycle_timeout ( & self ) -> Option < Duration > {
111
+ pub ( crate ) fn connection_recycle_timeout ( & self ) -> Duration {
96
112
self . connection_recycle_timeout
97
113
}
98
114
}
0 commit comments