@@ -486,7 +486,37 @@ impl Database for RedisDatabase {
486
486
subscription : & str ,
487
487
start_time : i64 ,
488
488
) -> Result < SubscriptionStatsCounters > {
489
- todo ! ( )
489
+ let fields = HashMap :: < RedisDomain , String > :: from ( [
490
+ ( RedisDomain :: Subscription , subscription. to_string ( ) ) ,
491
+ ] ) ;
492
+ let heartbeats = self . get_heartbeats_by_field ( fields) . await ?;
493
+
494
+ let total_machines_count = i64:: try_from ( heartbeats. len ( ) ) ?;
495
+ let mut alive_machines_count = 0 ;
496
+ let mut active_machines_count = 0 ;
497
+ let mut dead_machines_count = 0 ;
498
+
499
+ for hb in heartbeats. iter ( ) {
500
+ match hb {
501
+ HeartbeatData { last_seen, last_event_seen, ..} if MachineStatusFilter :: Alive . is_match ( last_seen, last_event_seen, start_time) => {
502
+ alive_machines_count += 1 ;
503
+ } ,
504
+ HeartbeatData { last_seen, last_event_seen, ..} if MachineStatusFilter :: Active . is_match ( last_seen, last_event_seen, start_time) => {
505
+ active_machines_count += 1 ;
506
+ } ,
507
+ HeartbeatData { last_seen, last_event_seen, ..} if MachineStatusFilter :: Dead . is_match ( last_seen, last_event_seen, start_time) => {
508
+ dead_machines_count += 1 ;
509
+ } ,
510
+ _ => { } ,
511
+ } ;
512
+ }
513
+
514
+ Ok ( SubscriptionStatsCounters :: new (
515
+ total_machines_count,
516
+ alive_machines_count,
517
+ active_machines_count,
518
+ dead_machines_count,
519
+ ) )
490
520
}
491
521
492
522
async fn get_machines (
@@ -495,6 +525,35 @@ impl Database for RedisDatabase {
495
525
start_time : i64 ,
496
526
stat_type : Option < SubscriptionMachineState > ,
497
527
) -> Result < Vec < SubscriptionMachine > > {
498
- todo ! ( )
528
+ let fields = HashMap :: < RedisDomain , String > :: from ( [
529
+ ( RedisDomain :: Subscription , subscription. to_string ( ) ) ,
530
+ ] ) ;
531
+ let heartbeats = self . get_heartbeats_by_field ( fields) . await ?;
532
+ let mut result = Vec :: < SubscriptionMachine > :: new ( ) ;
533
+
534
+ for hb in heartbeats. iter ( ) {
535
+
536
+ match stat_type {
537
+ None => { } ,
538
+ Some ( SubscriptionMachineState :: Active ) => {
539
+ if !MachineStatusFilter :: Active . is_match ( & hb. last_seen , & hb. last_event_seen , start_time) {
540
+ continue ;
541
+ }
542
+ } ,
543
+ Some ( SubscriptionMachineState :: Alive ) => {
544
+ if !MachineStatusFilter :: Alive . is_match ( & hb. last_seen , & hb. last_event_seen , start_time) {
545
+ continue ;
546
+ }
547
+ } ,
548
+ Some ( SubscriptionMachineState :: Dead ) => {
549
+ if !MachineStatusFilter :: Dead . is_match ( & hb. last_seen , & hb. last_event_seen , start_time) {
550
+ continue ;
551
+ }
552
+ } ,
553
+ }
554
+ result. push ( SubscriptionMachine :: new ( hb. machine ( ) . to_string ( ) , hb. ip ( ) . to_string ( ) ) ) ;
555
+ }
556
+
557
+ Ok ( result)
499
558
}
500
559
}
0 commit comments