@@ -29,6 +29,12 @@ use super::serializable_event::SerializableEventData;
2929/// Stores the Unix timestamp (in seconds) of the last event received from the ring
3030type LastEventTime = Arc < AtomicU64 > ;
3131
32+ /// Seconds without events before health check reports unhealthy
33+ const UNHEALTHY_THRESHOLD_SECS : u64 = 10 ;
34+
35+ /// Seconds without events before triggering process exit
36+ const EXIT_THRESHOLD_SECS : u64 = 30 ;
37+
3238#[ derive( Debug , Clone , Serialize , Deserialize ) ]
3339pub struct TopAccessesData {
3440 pub account : Vec < AccessEntry < Address > > ,
@@ -368,13 +374,28 @@ async fn health_handler(
368374 . unwrap_or_default ( )
369375 . as_secs ( ) ;
370376 let last_event = last_event_time. load ( Ordering :: Relaxed ) ;
371- let is_healthy = now_secs. saturating_sub ( last_event) <= 10 ;
377+ let time_since_last_event = now_secs. saturating_sub ( last_event) ;
378+
379+ // Exit process if no events received for EXIT_THRESHOLD_SECS
380+ if time_since_last_event >= EXIT_THRESHOLD_SECS {
381+ error ! (
382+ "No events received for {} seconds (threshold: {}), exiting to trigger restart" ,
383+ time_since_last_event,
384+ EXIT_THRESHOLD_SECS
385+ ) ;
386+ std:: process:: exit ( 1 ) ;
387+ }
388+
389+ let is_healthy = time_since_last_event <= UNHEALTHY_THRESHOLD_SECS ;
372390
373391 let body = if is_healthy {
374392 info ! ( "Health check passed" ) ;
375393 r#"{"success": true}"#
376394 } else {
377- warn ! ( "Health check failed - last event time: {} seconds ago" , now_secs. saturating_sub( last_event) ) ;
395+ warn ! (
396+ "Health check failed - last event time: {} seconds ago" ,
397+ time_since_last_event
398+ ) ;
378399 r#"{"success": false}"#
379400 } ;
380401
0 commit comments