@@ -551,6 +551,12 @@ impl Simulation {
551
551
552
552
let result_logger = Arc :: new ( Mutex :: new ( PaymentResultLogger :: new ( ) ) ) ;
553
553
554
+ tasks. spawn ( run_results_logger (
555
+ listener. clone ( ) ,
556
+ result_logger. clone ( ) ,
557
+ Duration :: from_secs ( 60 ) ,
558
+ ) ) ;
559
+
554
560
tasks. spawn ( consume_simulation_results (
555
561
result_logger,
556
562
results_receiver,
@@ -946,22 +952,17 @@ async fn write_payment_results(
946
952
}
947
953
}
948
954
949
- /// PaymentResultLogger is an aggregate logger that will report on a summary of the payments that have been reported
950
- /// to it at regular intervals (defined by the log_interval it is created with).
955
+ /// PaymentResultLogger is an aggregate logger that will report on a summary of the payments that have been reported.
951
956
#[ derive( Default ) ]
952
957
struct PaymentResultLogger {
953
958
success_payment : u64 ,
954
959
failed_payment : u64 ,
955
960
total_sent : u64 ,
956
- call_count : u8 ,
957
- log_interval : u8 ,
958
961
}
959
962
960
963
impl PaymentResultLogger {
961
964
fn new ( ) -> Self {
962
965
PaymentResultLogger {
963
- // TODO: set the interval at which we log based on the number of payment we're expecting to log.
964
- log_interval : 10 ,
965
966
..Default :: default ( )
966
967
}
967
968
}
@@ -973,18 +974,44 @@ impl PaymentResultLogger {
973
974
}
974
975
975
976
self . total_sent += details. amount_msat ;
976
- self . call_count += 1 ;
977
+ }
978
+ }
977
979
978
- if self . call_count % self . log_interval == 0 || self . call_count == 0 {
979
- let total_payments = self . success_payment + self . failed_payment ;
980
- log:: info!(
981
- "Processed {} payments sending {} msat total with {}% success rate." ,
982
- total_payments,
983
- self . total_sent,
984
- ( self . success_payment * 100 / total_payments)
985
- ) ;
980
+ impl Display for PaymentResultLogger {
981
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
982
+ let total_payments = self . success_payment + self . failed_payment ;
983
+ write ! (
984
+ f,
985
+ "Processed {} payments sending {} msat total with {:.2}% success rate." ,
986
+ total_payments,
987
+ self . total_sent,
988
+ ( self . success_payment as f64 / total_payments as f64 ) * 100.0
989
+ )
990
+ }
991
+ }
992
+
993
+ async fn run_results_logger (
994
+ listener : Listener ,
995
+ logger : Arc < Mutex < PaymentResultLogger > > ,
996
+ interval : Duration ,
997
+ ) {
998
+ log:: debug!( "Results logger started." ) ;
999
+ log:: info!( "Summary of results will be reported every {:?}." , interval) ;
1000
+
1001
+ loop {
1002
+ select ! {
1003
+ biased;
1004
+ _ = listener. clone( ) => {
1005
+ break
1006
+ }
1007
+
1008
+ _ = time:: sleep( interval) => {
1009
+ log:: info!( "{}" , logger. lock( ) . await )
1010
+ }
986
1011
}
987
1012
}
1013
+
1014
+ log:: debug!( "Results logger stopped." )
988
1015
}
989
1016
990
1017
/// produce_results is responsible for receiving the outputs of events that the simulator has taken and
0 commit comments