@@ -10,13 +10,13 @@ use cli::Cli;
1010use std:: collections:: HashMap ;
1111use std:: time:: Duration ;
1212use tokio:: time:: Instant ;
13- use types:: { DatasetConfig , DatasetId , DatasetsConfig } ;
13+ use types:: { DatasetId , DatasetsConfig } ;
1414use url:: Url ;
1515
1616fn main ( ) -> anyhow:: Result < ( ) > {
1717 let args = Cli :: parse ( ) ;
1818
19- let datasets_config : DatasetsConfig = {
19+ let datasets : DatasetsConfig = {
2020 let contents = std:: fs:: read_to_string ( & args. datasets_config )
2121 . with_context ( || format ! ( "failed to read {}" , args. datasets_config. display( ) ) ) ?;
2222 serde_yaml:: from_str ( & contents)
@@ -33,7 +33,7 @@ fn main() -> anyhow::Result<()> {
3333 args. hotblocks_url ,
3434 args. status_url ,
3535 args. datasets_url ,
36- datasets_config . datasets ,
36+ datasets,
3737 Duration :: from_secs ( args. retain_delay_secs ) ,
3838 Duration :: from_secs ( args. datasets_update_interval_secs ) ,
3939 )
@@ -48,7 +48,7 @@ struct HotblocksRetain {
4848 hotblocks_url : Url ,
4949 status_url : Url ,
5050 datasets_url : Url ,
51- datasets : Vec < DatasetConfig > ,
51+ datasets : DatasetsConfig ,
5252 retain_delay : Duration ,
5353 datasets_update_interval : Duration ,
5454 name_to_id : HashMap < String , DatasetId > ,
@@ -60,7 +60,7 @@ impl HotblocksRetain {
6060 hotblocks_url : Url ,
6161 status_url : Url ,
6262 datasets_url : Url ,
63- datasets : Vec < DatasetConfig > ,
63+ datasets : DatasetsConfig ,
6464 retain_delay : Duration ,
6565 datasets_update_interval : Duration ,
6666 ) -> Self {
@@ -124,18 +124,14 @@ impl HotblocksRetain {
124124 . map ( |dataset| ( dataset. id . as_str ( ) , dataset. height ) )
125125 . collect :: < HashMap < _ , _ > > ( ) ;
126126
127- for dataset in & self . datasets {
128- let dataset_name = dataset. name . as_str ( ) ;
129- let dataset_id = if let Some ( id) = & dataset. id {
130- id. as_str ( )
127+ for ( dataset, props) in & self . datasets {
128+ let dataset_id = if let Some ( id) = props. as_ref ( ) . and_then ( |p| p. id . as_deref ( ) ) {
129+ id
131130 } else {
132- match self . name_to_id . get ( dataset_name ) {
131+ match self . name_to_id . get ( dataset ) {
133132 Some ( id) => id. as_str ( ) ,
134133 None => {
135- tracing:: warn!(
136- dataset = dataset_name,
137- "dataset not found in manifest, skipping"
138- ) ;
134+ tracing:: warn!( dataset, "dataset not found in manifest, skipping" ) ;
139135 continue ;
140136 }
141137 }
@@ -146,33 +142,24 @@ impl HotblocksRetain {
146142 match hotblocks:: set_retention (
147143 & self . client ,
148144 & self . hotblocks_url ,
149- dataset_name ,
145+ dataset ,
150146 * height,
151147 )
152148 . await
153149 {
154150 Ok ( ( ) ) => {
155- tracing:: info!(
156- dataset = dataset_name,
157- height,
158- "applied retention policy"
159- ) ;
151+ tracing:: info!( dataset, height, "applied retention policy" ) ;
160152 }
161153 Err ( err) => {
162- tracing:: warn!(
163- dataset = dataset_name,
164- height,
165- error = ?err,
166- "failed to apply retention"
167- ) ;
154+ tracing:: warn!( dataset, height, error = ?err, "failed to apply retention" ) ;
168155 }
169156 }
170157 }
171158 Some ( None ) => {
172- tracing:: info!( dataset = dataset_name , "dataset has no reported height yet" ) ;
159+ tracing:: info!( dataset, "dataset has no reported height yet" ) ;
173160 }
174161 None => {
175- tracing:: warn!( dataset = dataset_name , "dataset not found in status" ) ;
162+ tracing:: warn!( dataset, "dataset not found in status" ) ;
176163 }
177164 }
178165 }
0 commit comments