@@ -8,7 +8,7 @@ use anyhow::Context;
88use clap:: Parser ;
99use cli:: Cli ;
1010use std:: collections:: HashMap ;
11- use std:: time:: Duration ;
11+ use std:: time:: { Duration , SystemTime , UNIX_EPOCH } ;
1212use tokio:: time:: Instant ;
1313use types:: { DatasetId , DatasetsConfig } ;
1414use url:: Url ;
@@ -34,7 +34,6 @@ fn main() -> anyhow::Result<()> {
3434 args. status_url ,
3535 args. datasets_url ,
3636 datasets,
37- Duration :: from_secs ( args. retain_delay_secs ) ,
3837 Duration :: from_secs ( args. datasets_update_interval_secs ) ,
3938 )
4039 . run ( ) ,
@@ -49,10 +48,10 @@ struct HotblocksRetain {
4948 status_url : Url ,
5049 datasets_url : Url ,
5150 datasets : DatasetsConfig ,
52- retain_delay : Duration ,
5351 datasets_update_interval : Duration ,
5452 name_to_id : HashMap < String , DatasetId > ,
5553 last_datasets_refresh : Instant ,
54+ last_effective_from : Option < u64 > ,
5655}
5756
5857impl HotblocksRetain {
@@ -61,7 +60,6 @@ impl HotblocksRetain {
6160 status_url : Url ,
6261 datasets_url : Url ,
6362 datasets : DatasetsConfig ,
64- retain_delay : Duration ,
6563 datasets_update_interval : Duration ,
6664 ) -> Self {
6765 Self {
@@ -70,10 +68,10 @@ impl HotblocksRetain {
7068 status_url,
7169 datasets_url,
7270 datasets,
73- retain_delay,
7471 datasets_update_interval,
7572 name_to_id : HashMap :: new ( ) ,
7673 last_datasets_refresh : Instant :: now ( ) - datasets_update_interval,
74+ last_effective_from : None ,
7775 }
7876 }
7977
@@ -90,11 +88,25 @@ impl HotblocksRetain {
9088 }
9189 } ;
9290
93- tracing:: info!(
94- delay_secs = self . retain_delay. as_secs( ) ,
95- "fetched status, waiting before applying retention"
96- ) ;
97- tokio:: time:: sleep ( self . retain_delay ) . await ;
91+ let now = SystemTime :: now ( )
92+ . duration_since ( UNIX_EPOCH )
93+ . unwrap ( )
94+ . as_secs ( ) ;
95+
96+ if now < status. effective_from {
97+ if self . last_effective_from == Some ( status. effective_from ) {
98+ tracing:: info!( "effective_from unchanged, re-checking in 5 minutes" ) ;
99+ tokio:: time:: sleep ( Duration :: from_secs ( 300 ) ) . await ;
100+ continue ;
101+ }
102+
103+ self . last_effective_from = Some ( status. effective_from ) ;
104+ let wait_secs = status. effective_from - now;
105+ tracing:: info!( wait_secs, effective_from = status. effective_from, "waiting for effective time" ) ;
106+ tokio:: time:: sleep ( Duration :: from_secs ( wait_secs) ) . await ;
107+ } else {
108+ self . last_effective_from = Some ( status. effective_from ) ;
109+ }
98110
99111 self . apply_retention ( & status) . await ;
100112 }
0 commit comments