Skip to content

Commit 6eadd9a

Browse files
committed
some log fixes
1 parent d6b36ac commit 6eadd9a

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

compute/src/main.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use std::env;
2-
31
use dkn_compute::*;
42
use eyre::{Context, Result};
3+
use std::env;
54
use tokio_util::sync::CancellationToken;
65

76
#[tokio::main]
@@ -32,7 +31,7 @@ async fn main() -> Result<()> {
3231
let token = CancellationToken::new();
3332
let cancellation_token = token.clone();
3433
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()) {
3635
let duration_secs = timeout_str.parse().unwrap_or(120);
3736
log::warn!("Waiting for {} seconds before exiting.", duration_secs);
3837
tokio::time::sleep(tokio::time::Duration::from_secs(duration_secs)).await;
@@ -48,7 +47,7 @@ async fn main() -> Result<()> {
4847
let mut config = DriaComputeNodeConfig::new();
4948
config.assert_address_not_in_use()?;
5049
let service_check_token = token.clone();
51-
let service_check_handle = tokio::spawn(async move {
50+
let config = tokio::spawn(async move {
5251
tokio::select! {
5352
_ = service_check_token.cancelled() => {
5453
log::info!("Service check cancelled.");
@@ -63,10 +62,9 @@ async fn main() -> Result<()> {
6362
config
6463
}
6564
}
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")?;
7068

7169
if !token.is_cancelled() {
7270
// launch the node in a separate thread
@@ -95,6 +93,7 @@ async fn main() -> Result<()> {
9593
log::warn!("Not launching node due to early exit.");
9694
}
9795

96+
log::info!("Bye!");
9897
Ok(())
9998
}
10099

@@ -116,6 +115,8 @@ async fn wait_for_termination(cancellation: CancellationToken) -> Result<()> {
116115
return Ok(());
117116
}
118117
};
118+
119+
cancellation.cancel();
119120
}
120121

121122
#[cfg(windows)]
@@ -139,10 +140,18 @@ async fn wait_for_termination(cancellation: CancellationToken) -> Result<()> {
139140
return Ok(());
140141
}
141142
};
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();
142151
}
143152

144153
log::info!("Terminating the node...");
145-
cancellation.cancel();
154+
146155
Ok(())
147156
}
148157

0 commit comments

Comments
 (0)