1
+ use std:: env;
2
+
1
3
use dkn_compute:: * ;
2
- use eyre:: Result ;
4
+ use eyre:: { Context , Result } ;
3
5
use tokio_util:: sync:: CancellationToken ;
4
6
5
7
#[ tokio:: main]
6
8
async fn main ( ) -> Result < ( ) > {
7
- if let Err ( e) = dotenvy:: dotenv ( ) {
8
- log:: warn!( "Could not load .env file: {}" , e) ;
9
- }
10
-
9
+ let dotenv_result = dotenvy:: dotenv ( ) ;
11
10
env_logger:: builder ( )
12
11
. format_timestamp ( Some ( env_logger:: TimestampPrecision :: Millis ) )
13
12
. init ( ) ;
13
+ if let Err ( e) = dotenv_result {
14
+ log:: warn!( "Could not load .env file: {}" , e) ;
15
+ }
14
16
15
17
log:: info!(
16
18
r#"
@@ -26,49 +28,45 @@ async fn main() -> Result<()> {
26
28
27
29
let token = CancellationToken :: new ( ) ;
28
30
let cancellation_token = token. clone ( ) ;
29
- // add cancellation check
30
31
tokio:: spawn ( async move {
31
- // FIXME: weird feature-gating here bugs with IDE, fix this later
32
- #[ cfg( feature = "profiling" ) ]
33
- {
34
- const PROFILE_DURATION_SECS : u64 = 120 ;
35
- tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( PROFILE_DURATION_SECS ) ) . await ;
32
+ if let Some ( timeout_str) = env:: var ( "DKN_EXIT_TIMEOUT" ) . ok ( ) {
33
+ // add cancellation check
34
+ let duration_secs = timeout_str. parse ( ) . unwrap_or ( 120 ) ;
35
+ tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( duration_secs) ) . await ;
36
36
cancellation_token. cancel ( ) ;
37
+ } else {
38
+ if let Err ( err) = wait_for_termination ( cancellation_token. clone ( ) ) . await {
39
+ log:: error!( "Error waiting for termination: {:?}" , err) ;
40
+ log:: error!( "Cancelling due to unexpected error." ) ;
41
+ cancellation_token. cancel ( ) ;
42
+ } ;
37
43
}
38
-
39
- #[ cfg( not( feature = "profiling" ) ) ]
40
- if let Err ( err) = wait_for_termination ( cancellation_token. clone ( ) ) . await {
41
- log:: error!( "Error waiting for termination: {:?}" , err) ;
42
- log:: error!( "Cancelling due to unexpected error." ) ;
43
- cancellation_token. cancel ( ) ;
44
- } ;
45
44
} ) ;
46
45
47
- // create configurations & check required services
48
- let config = DriaComputeNodeConfig :: new ( ) ;
46
+ // create configurations & check required services & address in use
47
+ let mut config = DriaComputeNodeConfig :: new ( ) ;
49
48
config. assert_address_not_in_use ( ) ?;
50
49
let service_check_token = token. clone ( ) ;
51
- let mut config_clone = config. clone ( ) ;
52
50
let service_check_handle = tokio:: spawn ( async move {
53
51
tokio:: select! {
54
52
_ = service_check_token. cancelled( ) => {
55
53
log:: info!( "Service check cancelled." ) ;
54
+ config
56
55
}
57
- result = config_clone . workflows. check_services( ) => {
56
+ result = config . workflows. check_services( ) => {
58
57
if let Err ( err) = result {
59
58
log:: error!( "Error checking services: {:?}" , err) ;
60
59
panic!( "Service check failed." )
61
60
}
61
+ config
62
62
}
63
63
}
64
64
} ) ;
65
+ let config = service_check_handle
66
+ . await
67
+ . wrap_err ( "error during service checks" ) ?;
65
68
66
- // wait for service check to complete
67
- if let Err ( err) = service_check_handle. await {
68
- log:: error!( "Service check handle error: {}" , err) ;
69
- panic ! ( "Could not exit service check thread handle." ) ;
70
- } ;
71
-
69
+ log:: warn!( "Using models: {:#?}" , config. workflows. models) ;
72
70
if !token. is_cancelled ( ) {
73
71
// launch the node
74
72
let node_token = token. clone ( ) ;
@@ -97,11 +95,9 @@ async fn main() -> Result<()> {
97
95
Ok ( ( ) )
98
96
}
99
97
100
- // FIXME: remove this `unused` once we have a better way to handle this
101
98
/// Waits for various termination signals, and cancels the given token when the signal is received.
102
99
///
103
100
/// Handles Unix and Windows [target families](https://doc.rust-lang.org/reference/conditional-compilation.html#target_family).
104
- #[ allow( unused) ]
105
101
async fn wait_for_termination ( cancellation : CancellationToken ) -> Result < ( ) > {
106
102
#[ cfg( unix) ]
107
103
{
0 commit comments