@@ -3,7 +3,7 @@ use clap::{CommandFactory, Parser, Subcommand};
3
3
use config:: { Map , Value } ;
4
4
5
5
use slog:: { o, Drain , Level , Logger } ;
6
- use slog_scope:: { crit, debug} ;
6
+ use slog_scope:: { crit, debug, info } ;
7
7
use std:: path:: PathBuf ;
8
8
use std:: sync:: Arc ;
9
9
use std:: time:: Duration ;
@@ -80,6 +80,11 @@ pub struct Args {
80
80
/// Will be ignored on (pre)production networks.
81
81
#[ clap( long) ]
82
82
allow_unparsable_block : bool ,
83
+
84
+ /// Preloading refresh interval in seconds
85
+ // TODO: Replace the default value to 43200 (12 hours) once the Cardano transactions is activated on mainnet
86
+ #[ clap( long, env = "PRELOADING_REFRESH_INTERVAL" , default_value_t = 7200 ) ]
87
+ preloading_refresh_interval : u64 ,
83
88
}
84
89
85
90
impl Args {
@@ -184,7 +189,17 @@ async fn main() -> StdResult<()> {
184
189
. map ( |_| None )
185
190
} ) ;
186
191
187
- let preload_task = tokio:: spawn ( async move { cardano_transaction_preloader. preload ( ) . await } ) ;
192
+ join_set. spawn ( async move {
193
+ let refresh_interval = config. preloading_refresh_interval ;
194
+ let mut interval = tokio:: time:: interval ( Duration :: from_secs ( refresh_interval) ) ;
195
+ loop {
196
+ interval. tick ( ) . await ;
197
+ if let Err ( err) = cardano_transaction_preloader. preload ( ) . await {
198
+ crit ! ( "🔥 Cardano transactions preloader failed: {err:?}" ) ;
199
+ }
200
+ info ! ( "⟳ Next Preload Cardano Transactions will start in {refresh_interval} s" , ) ;
201
+ }
202
+ } ) ;
188
203
189
204
let ( metrics_server_shutdown_tx, metrics_server_shutdown_rx) = oneshot:: channel ( ) ;
190
205
if config. enable_metrics_server {
@@ -239,10 +254,6 @@ async fn main() -> StdResult<()> {
239
254
. send ( ( ) )
240
255
. map_err ( |e| anyhow ! ( "Metrics server shutdown signal could not be sent: {e:?}" ) ) ?;
241
256
242
- if !preload_task. is_finished ( ) {
243
- preload_task. abort ( ) ;
244
- }
245
-
246
257
join_set. shutdown ( ) . await ;
247
258
248
259
debug ! ( "Stopping" ; "shutdown_reason" => shutdown_reason) ;
0 commit comments