1
+ use log:: * ;
1
2
use std:: time:: Duration ;
2
3
3
4
pub mod env_reader;
@@ -19,55 +20,53 @@ pub fn wait(
19
20
config : & Config ,
20
21
on_timeout : & mut dyn FnMut ( ) ,
21
22
) {
22
- println ! ( "{}" , LINE_SEPARATOR ) ;
23
- println ! ( " docker-compose-wait {}" , env!( "CARGO_PKG_VERSION" ) ) ;
24
- println ! ( "---------------------------" ) ;
25
- println ! ( "Starting with configuration:" ) ;
26
- println ! ( " - Hosts to be waiting for: [{}]" , config. hosts) ;
27
- println ! (
23
+ info ! ( "{}" , LINE_SEPARATOR ) ;
24
+ info ! ( " docker-compose-wait {}" , env!( "CARGO_PKG_VERSION" ) ) ;
25
+ info ! ( "---------------------------" ) ;
26
+ debug ! ( "Starting with configuration:" ) ;
27
+ debug ! ( " - Hosts to be waiting for: [{}]" , config. hosts) ;
28
+ debug ! (
28
29
" - Timeout before failure: {} seconds " ,
29
30
config. global_timeout
30
31
) ;
31
- println ! (
32
+ debug ! (
32
33
" - TCP connection timeout before retry: {} seconds " ,
33
34
config. tcp_connection_timeout
34
35
) ;
35
- println ! (
36
+ debug ! (
36
37
" - Sleeping time before checking for hosts availability: {} seconds" ,
37
38
config. wait_before
38
39
) ;
39
- println ! (
40
+ debug ! (
40
41
" - Sleeping time once all hosts are available: {} seconds" ,
41
42
config. wait_after
42
43
) ;
43
- println ! (
44
+ debug ! (
44
45
" - Sleeping time between retries: {} seconds" ,
45
46
config. wait_sleep_interval
46
47
) ;
47
- println ! ( "{}" , LINE_SEPARATOR ) ;
48
+ debug ! ( "{}" , LINE_SEPARATOR ) ;
48
49
49
50
if config. wait_before > 0 {
50
- println ! (
51
+ info ! (
51
52
"Waiting {} seconds before checking for hosts availability" ,
52
53
config. wait_before
53
54
) ;
54
- println ! ( "{}" , LINE_SEPARATOR ) ;
55
+ info ! ( "{}" , LINE_SEPARATOR ) ;
55
56
sleep. sleep ( config. wait_before ) ;
56
57
}
57
58
58
59
if !config. hosts . trim ( ) . is_empty ( ) {
59
60
sleep. reset ( ) ;
60
61
for host in config. hosts . trim ( ) . split ( ',' ) {
61
- println ! ( "Checking availability of {}" , host) ;
62
+ info ! ( "Checking availability of {}" , host) ;
62
63
while !port_check:: is_port_reachable_with_timeout (
63
- & host
64
- . trim ( )
65
- . to_string ( ) ,
64
+ & host. trim ( ) . to_string ( ) ,
66
65
Duration :: from_secs ( config. tcp_connection_timeout ) ,
67
66
) {
68
- println ! ( "Host {} not yet available..." , host) ;
67
+ info ! ( "Host {} not yet available..." , host) ;
69
68
if sleep. elapsed ( config. global_timeout ) {
70
- println ! (
69
+ error ! (
71
70
"Timeout! After {} seconds some hosts are still not reachable" ,
72
71
config. global_timeout
73
72
) ;
@@ -76,22 +75,22 @@ pub fn wait(
76
75
}
77
76
sleep. sleep ( config. wait_sleep_interval ) ;
78
77
}
79
- println ! ( "Host {} is now available!" , host) ;
80
- println ! ( "{}" , LINE_SEPARATOR ) ;
78
+ info ! ( "Host {} is now available!" , host) ;
79
+ info ! ( "{}" , LINE_SEPARATOR ) ;
81
80
}
82
81
}
83
82
84
83
if config. wait_after > 0 {
85
- println ! (
84
+ info ! (
86
85
"Waiting {} seconds after hosts availability" ,
87
86
config. wait_after
88
87
) ;
89
- println ! ( "{}" , LINE_SEPARATOR ) ;
88
+ info ! ( "{}" , LINE_SEPARATOR ) ;
90
89
sleep. sleep ( config. wait_after ) ;
91
90
}
92
91
93
- println ! ( "docker-compose-wait - Everything's fine, the application can now start!" ) ;
94
- println ! ( "{}" , LINE_SEPARATOR ) ;
92
+ info ! ( "docker-compose-wait - Everything's fine, the application can now start!" ) ;
93
+ info ! ( "{}" , LINE_SEPARATOR ) ;
95
94
}
96
95
97
96
pub fn config_from_env ( ) -> Config {
0 commit comments