@@ -11,14 +11,14 @@ use crate::RuntimeRequestSink;
11
11
use futures:: channel:: mpsc;
12
12
use futures:: prelude:: * ;
13
13
use futures:: stream:: FuturesUnordered ;
14
- use log:: debug;
15
- use log:: error;
16
- use log:: info;
17
14
use std:: collections:: HashMap ;
18
15
use std:: panic;
19
16
use std:: time:: Duration ;
20
17
use tokio:: task:: JoinError ;
21
18
use tokio:: task:: JoinHandle ;
19
+ use tracing:: debug;
20
+ use tracing:: error;
21
+ use tracing:: info;
22
22
23
23
/// Actions sent by actors to the runtime
24
24
#[ derive( Debug ) ]
@@ -95,7 +95,7 @@ impl Runtime {
95
95
/// and all the running tasks have reach completion (successfully or not).
96
96
pub async fn run_to_completion ( self ) -> Result < ( ) , RuntimeError > {
97
97
if let Err ( err) = Runtime :: wait_for_completion ( self . bg_task ) . await {
98
- error ! ( "Aborted due to {err}" ) ;
98
+ error ! ( target : "Actors" , "Aborted due to {err}" ) ;
99
99
std:: process:: exit ( 1 )
100
100
}
101
101
@@ -138,7 +138,7 @@ impl RuntimeHandle {
138
138
139
139
/// Send an action to the runtime
140
140
async fn send ( & mut self , action : RuntimeAction ) -> Result < ( ) , ChannelError > {
141
- debug ! ( target: "Runtime " , "schedule {:?}" , action) ;
141
+ debug ! ( target: "Actors " , "schedule {:?}" , action) ;
142
142
self . actions_sender . send ( action) . await ?;
143
143
Ok ( ( ) )
144
144
}
@@ -175,7 +175,7 @@ impl RuntimeActor {
175
175
}
176
176
177
177
async fn run ( mut self ) -> Result < ( ) , RuntimeError > {
178
- info ! ( target: "Runtime " , "Started" ) ;
178
+ info ! ( target: "Actors " , "Started" ) ;
179
179
let mut aborting_error = None ;
180
180
let mut actors_count: usize = 0 ;
181
181
loop {
@@ -186,7 +186,7 @@ impl RuntimeActor {
186
186
match action {
187
187
RuntimeAction :: Spawn ( actor) => {
188
188
let running_name = format!( "{}-{}" , actor. name( ) , actors_count) ;
189
- info!( target: "Runtime " , "Running {running_name}" ) ;
189
+ info!( target: "Actors " , "Running {running_name}" ) ;
190
190
self . send_event( RuntimeEvent :: Started {
191
191
task: running_name. clone( ) ,
192
192
} )
@@ -196,22 +196,22 @@ impl RuntimeActor {
196
196
actors_count += 1 ;
197
197
}
198
198
RuntimeAction :: Shutdown => {
199
- info!( target: "Runtime " , "Shutting down" ) ;
199
+ info!( target: "Actors " , "Shutting down" ) ;
200
200
shutdown_actors( & mut self . running_actors) . await ;
201
201
break ;
202
202
}
203
203
}
204
204
}
205
205
None => {
206
- info!( target: "Runtime " , "Runtime actions channel closed, runtime stopping" ) ;
206
+ info!( target: "Actors " , "Runtime actions channel closed, runtime stopping" ) ;
207
207
shutdown_actors( & mut self . running_actors) . await ;
208
208
break ;
209
209
}
210
210
}
211
211
} ,
212
212
Some ( finished_actor) = self . futures. next( ) => {
213
213
if let Err ( error) = self . handle_actor_finishing( finished_actor) . await {
214
- info!( target: "Runtime " , "Shutting down on error: {error}" ) ;
214
+ info!( target: "Actors " , "Shutting down on error: {error}" ) ;
215
215
aborting_error = Some ( error) ;
216
216
shutdown_actors( & mut self . running_actors) . await ;
217
217
break
@@ -222,12 +222,12 @@ impl RuntimeActor {
222
222
223
223
tokio:: select! {
224
224
_ = tokio:: time:: sleep( self . cleanup_duration) => {
225
- error!( target: "Runtime " , "Timeout waiting for all actors to shutdown" ) ;
225
+ error!( target: "Actors " , "Timeout waiting for all actors to shutdown" ) ;
226
226
for still_running in self . running_actors. keys( ) {
227
- error!( target: "Runtime " , "Failed to shutdown: {still_running}" )
227
+ error!( target: "Actors " , "Failed to shutdown: {still_running}" )
228
228
}
229
229
}
230
- _ = self . wait_for_actors_to_finish( ) => info!( target: "Runtime " , "All actors have finished" )
230
+ _ = self . wait_for_actors_to_finish( ) => info!( target: "Actors " , "All actors have finished" )
231
231
}
232
232
233
233
match aborting_error {
@@ -248,18 +248,18 @@ impl RuntimeActor {
248
248
) -> Result < ( ) , RuntimeError > {
249
249
match finished_actor {
250
250
Err ( e) => {
251
- error ! ( target: "Runtime " , "Failed to execute actor: {e}" ) ;
251
+ error ! ( target: "Actors " , "Failed to execute actor: {e}" ) ;
252
252
Err ( RuntimeError :: JoinError ( e) )
253
253
}
254
254
Ok ( Ok ( actor) ) => {
255
255
self . running_actors . remove ( & actor) ;
256
- info ! ( target: "Runtime " , "Actor has finished: {actor}" ) ;
256
+ info ! ( target: "Actors " , "Actor has finished: {actor}" ) ;
257
257
self . send_event ( RuntimeEvent :: Stopped { task : actor } ) . await ;
258
258
Ok ( ( ) )
259
259
}
260
260
Ok ( Err ( ( actor, error) ) ) => {
261
261
self . running_actors . remove ( & actor) ;
262
- error ! ( target: "Runtime " , "Actor {actor} has finished unsuccessfully: {error:?}" ) ;
262
+ error ! ( target: "Actors " , "Actor {actor} has finished unsuccessfully: {error:?}" ) ;
263
263
self . send_event ( RuntimeEvent :: Aborted {
264
264
task : actor. clone ( ) ,
265
265
error : format ! ( "{error}" ) ,
@@ -273,7 +273,7 @@ impl RuntimeActor {
273
273
async fn send_event ( & mut self , event : RuntimeEvent ) {
274
274
if let Some ( events) = & mut self . events {
275
275
if let Err ( e) = events. send ( event) . await {
276
- error ! ( target: "Runtime " , "Failed to send RuntimeEvent: {e}" ) ;
276
+ error ! ( target: "Actors " , "Failed to send RuntimeEvent: {e}" ) ;
277
277
}
278
278
}
279
279
}
@@ -286,10 +286,10 @@ where
286
286
for ( running_as, sender) in a {
287
287
match sender. send ( RuntimeRequest :: Shutdown ) . await {
288
288
Ok ( ( ) ) => {
289
- debug ! ( target: "Runtime " , "Successfully sent shutdown request to {running_as}" )
289
+ debug ! ( target: "Actors " , "Successfully sent shutdown request to {running_as}" )
290
290
}
291
291
Err ( e) => {
292
- error ! ( target: "Runtime " , "Failed to send shutdown request to {running_as}: {e:?}" )
292
+ error ! ( target: "Actors " , "Failed to send shutdown request to {running_as}: {e:?}" )
293
293
}
294
294
}
295
295
}
0 commit comments