diff --git a/src/events/mod.rs b/src/events/mod.rs index e46db99..edb5e05 100644 --- a/src/events/mod.rs +++ b/src/events/mod.rs @@ -63,24 +63,19 @@ where pub async fn listen(&mut self, got_hit: &mut bool) -> Result<()> { loop { + // always flush in case some blocks were finalized before reconnecting + if let Err(err) = self.cache.flush().await { + log::error!("failed to flush redis cache {}", err); + tokio::time::sleep(Duration::from_millis(500)).await; + continue; + } select! { _ = tokio::signal::ctrl_c() => { log::info!("shutting down listener gracefully"); - if let Err(err) = self.cache.flush().await { - log::error!("failed to flush redis cache {}", err); - tokio::time::sleep(Duration::from_millis(500)).await; - continue; - } break; }, - result = self.cache.flush() => { - // always flush in case some blocks were finalized before reconnecting + result = self.handle_events() => { if let Err(err) = result { - log::error!("failed to flush redis cache {}", err); - tokio::time::sleep(Duration::from_millis(500)).await; - continue; - } - if let Err(err) = self.handle_events().await { log::error!("error listening to events {}", err); if let Some(subxt::Error::Rpc(_)) = err.downcast_ref::() { self.api = Self::connect(&mut self.substrate_urls).await?;