From b35cbe95ee347045d575b7879f097fd6fe4e2095 Mon Sep 17 00:00:00 2001 From: Lucas Colombo Date: Fri, 21 Jun 2024 12:56:39 -0300 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=94=A8=20remove=20comments=20?= =?UTF-8?q?about=20callbacks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/rustlers/rustler.rs | 25 +++++++------------------ lib/rustlers/svc.rs | 5 +++++ 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/lib/rustlers/rustler.rs b/lib/rustlers/rustler.rs index b9100c0..2e4b300 100644 --- a/lib/rustlers/rustler.rs +++ b/lib/rustlers/rustler.rs @@ -319,24 +319,8 @@ pub trait Rustler: RustlerAccessor + Send + Sync { /// should be called after the status of the rustler changes fn handle_status_change(&mut self) -> Result<()> { match self.status() { - RustlerStatus::Disconnected => { - self.set_last_stop(Some(Local::now())); - - // if let Some(callbacks) = self.callbacks() { - // if let Some(on_disconnected) = callbacks.on_disconnected { - // on_disconnected()?; - // } - // } - } - RustlerStatus::Connected => { - self.set_last_run(Some(Local::now())); - - // if let Some(callbacks) = self.callbacks() { - // if let Some(on_connected) = callbacks.on_connected { - // on_connected()?; - // } - // } - } + RustlerStatus::Disconnected => self.set_last_stop(Some(Local::now())), + RustlerStatus::Connected => self.set_last_run(Some(Local::now())), _ => {} }; @@ -433,6 +417,11 @@ macro_rules! rustler_accessors { fn next_run(&self) -> &$crate::rustlers::chrono::DateTime<$crate::rustlers::chrono::Local> { &self.next_run } + // TODO: Instead of next_run and next_stop, store the scheduling rules + // we can calculate the next run and next stop times from the rules, and will also be + // useful to decide if we should recover from a disconnection or not (we should only + // recover if the rules say we should be connected at the current time, otherwise we + // should stay disconnected, even if it was an abnormal disconnection) fn set_next_run( &mut self, next_run: $crate::rustlers::chrono::DateTime<$crate::rustlers::chrono::Local>, diff --git a/lib/rustlers/svc.rs b/lib/rustlers/svc.rs index 9e1347b..465c92d 100644 --- a/lib/rustlers/svc.rs +++ b/lib/rustlers/svc.rs @@ -112,6 +112,11 @@ where let mut publisher = self.publisher.clone(); while let Some(msg) = receiver.recv().await { match msg { + // TODO: if we want to restart a dead rustler, we should listen for a restart + // signal here and restart the rustler. The restart signal does not exist + // yet, so we will need to implement it and send it from rustlers when + // it makes sense to restart them (when we are sure we are not going to + // keep listening for quotes from the source feed, for example) RustlerMsg::QuoteMsg(quote) => publisher.publish(quote).await?, } }