1
1
use dkn_compute:: * ;
2
- use eyre:: { Context , Result } ;
2
+ use eyre:: Result ;
3
3
use std:: env;
4
4
use tokio_util:: sync:: CancellationToken ;
5
5
@@ -25,7 +25,7 @@ async fn main() -> Result<()> {
25
25
██║ ██║██╔══██╗██║██╔══██║ https://dria.co
26
26
██████╔╝██║ ██║██║██║ ██║
27
27
╚═════╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝
28
- "# ,
28
+ "#
29
29
) ;
30
30
31
31
let token = CancellationToken :: new ( ) ;
@@ -52,10 +52,6 @@ async fn main() -> Result<()> {
52
52
let service_check_token = token. clone ( ) ;
53
53
let config = tokio:: spawn ( async move {
54
54
tokio:: select! {
55
- _ = service_check_token. cancelled( ) => {
56
- log:: info!( "Service check cancelled." ) ;
57
- config
58
- }
59
55
result = config. workflows. check_services( ) => {
60
56
if let Err ( err) = result {
61
57
log:: error!( "Error checking services: {:?}" , err) ;
@@ -64,38 +60,44 @@ async fn main() -> Result<()> {
64
60
log:: warn!( "Using models: {:#?}" , config. workflows. models) ;
65
61
config
66
62
}
63
+ _ = service_check_token. cancelled( ) => {
64
+ log:: info!( "Service check cancelled." ) ;
65
+ config
66
+ }
67
67
}
68
68
} )
69
- . await
70
- . wrap_err ( "error during service checks" ) ?;
71
-
72
- if !token. is_cancelled ( ) {
73
- // launch the node in a separate thread
74
- let node_token = token. clone ( ) ;
75
- let node_handle = tokio:: spawn ( async move {
76
- match DriaComputeNode :: new ( config, node_token) . await {
77
- Ok ( mut node) => {
78
- if let Err ( err) = node. launch ( ) . await {
79
- log:: error!( "Node launch error: {}" , err) ;
80
- panic ! ( "Node failed." )
81
- } ;
82
- }
83
- Err ( err) => {
84
- log:: error!( "Node setup error: {}" , err) ;
85
- panic ! ( "Could not setup node." )
86
- }
87
- }
88
- } ) ;
69
+ . await ?;
89
70
90
- // wait for tasks to complete
91
- if let Err ( err) = node_handle. await {
92
- log:: error!( "Node handle error: {}" , err) ;
93
- panic ! ( "Could not exit Node thread handle." ) ;
94
- } ;
95
- } else {
96
- log:: warn!( "Not launching node due to early exit." ) ;
71
+ // check early exit due to failed service check
72
+ if token. is_cancelled ( ) {
73
+ log:: warn!( "Not launching node due to early exit, bye!" ) ;
74
+ return Ok ( ( ) ) ;
97
75
}
98
76
77
+ let node_token = token. clone ( ) ;
78
+ let ( mut node, p2p) = DriaComputeNode :: new ( config, node_token) . await ?;
79
+
80
+ // launch the p2p in a separate thread
81
+ log:: info!( "Spawning peer-to-peer client thread." ) ;
82
+ let p2p_handle = tokio:: spawn ( async move { p2p. run ( ) . await } ) ;
83
+
84
+ // launch the node in a separate thread
85
+ log:: info!( "Spawning compute node thread." ) ;
86
+ let node_handle = tokio:: spawn ( async move {
87
+ if let Err ( err) = node. launch ( ) . await {
88
+ log:: error!( "Node launch error: {}" , err) ;
89
+ panic ! ( "Node failed." )
90
+ } ;
91
+ } ) ;
92
+
93
+ // wait for tasks to complete
94
+ if let Err ( err) = node_handle. await {
95
+ log:: error!( "Node handle error: {}" , err) ;
96
+ } ;
97
+ if let Err ( err) = p2p_handle. await {
98
+ log:: error!( "P2P handle error: {}" , err) ;
99
+ } ;
100
+
99
101
log:: info!( "Bye!" ) ;
100
102
Ok ( ( ) )
101
103
}
@@ -158,6 +160,7 @@ async fn wait_for_termination(cancellation: CancellationToken) -> Result<()> {
158
160
Ok ( ( ) )
159
161
}
160
162
163
+ // #[deprecated]
161
164
/// Very CRUDE fix due to launcher log level bug
162
165
///
163
166
/// TODO: remove me later when the launcher is fixed
0 commit comments