1
- use std:: env;
2
-
3
1
use dkn_compute:: * ;
4
2
use eyre:: { Context , Result } ;
3
+ use std:: env;
5
4
use tokio_util:: sync:: CancellationToken ;
6
5
7
6
#[ tokio:: main]
@@ -32,7 +31,7 @@ async fn main() -> Result<()> {
32
31
let token = CancellationToken :: new ( ) ;
33
32
let cancellation_token = token. clone ( ) ;
34
33
tokio:: spawn ( async move {
35
- if let Ok ( timeout_str) = env:: var ( "DKN_EXIT_TIMEOUT" ) {
34
+ if let Ok ( timeout_str) = env:: var ( "DKN_EXIT_TIMEOUT" ) . map ( |s| s . trim ( ) . to_string ( ) ) {
36
35
let duration_secs = timeout_str. parse ( ) . unwrap_or ( 120 ) ;
37
36
log:: warn!( "Waiting for {} seconds before exiting." , duration_secs) ;
38
37
tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( duration_secs) ) . await ;
@@ -48,7 +47,7 @@ async fn main() -> Result<()> {
48
47
let mut config = DriaComputeNodeConfig :: new ( ) ;
49
48
config. assert_address_not_in_use ( ) ?;
50
49
let service_check_token = token. clone ( ) ;
51
- let service_check_handle = tokio:: spawn ( async move {
50
+ let config = tokio:: spawn ( async move {
52
51
tokio:: select! {
53
52
_ = service_check_token. cancelled( ) => {
54
53
log:: info!( "Service check cancelled." ) ;
@@ -63,10 +62,9 @@ async fn main() -> Result<()> {
63
62
config
64
63
}
65
64
}
66
- } ) ;
67
- let config = service_check_handle
68
- . await
69
- . wrap_err ( "error during service checks" ) ?;
65
+ } )
66
+ . await
67
+ . wrap_err ( "error during service checks" ) ?;
70
68
71
69
if !token. is_cancelled ( ) {
72
70
// launch the node in a separate thread
@@ -95,6 +93,7 @@ async fn main() -> Result<()> {
95
93
log:: warn!( "Not launching node due to early exit." ) ;
96
94
}
97
95
96
+ log:: info!( "Bye!" ) ;
98
97
Ok ( ( ) )
99
98
}
100
99
@@ -116,6 +115,8 @@ async fn wait_for_termination(cancellation: CancellationToken) -> Result<()> {
116
115
return Ok ( ( ) ) ;
117
116
}
118
117
} ;
118
+
119
+ cancellation. cancel ( ) ;
119
120
}
120
121
121
122
#[ cfg( windows) ]
@@ -139,10 +140,18 @@ async fn wait_for_termination(cancellation: CancellationToken) -> Result<()> {
139
140
return Ok ( ( ) ) ;
140
141
}
141
142
} ;
143
+
144
+ cancellation. cancel ( ) ;
145
+ }
146
+
147
+ #[ cfg( not( any( unix, windows) ) ) ]
148
+ {
149
+ log:: error!( "No signal handling for this platform: {}" , env:: consts:: OS ) ;
150
+ cancellation. cancel ( ) ;
142
151
}
143
152
144
153
log:: info!( "Terminating the node..." ) ;
145
- cancellation . cancel ( ) ;
154
+
146
155
Ok ( ( ) )
147
156
}
148
157
0 commit comments