From 6a8111a5f832dfba101d6f5eac41f005ceba6336 Mon Sep 17 00:00:00 2001
From: RustyNova <50844553+RustyNova016@users.noreply.github.com>
Date: Tue, 18 Mar 2025 14:19:41 +0000
Subject: [PATCH 01/10] refactor: Poller cleanup
---
src/app/mod.rs | 2 +-
src/poller/looper.rs | 95 +++++++++++++++++++++++++++++++-------------
src/poller/mod.rs | 69 +++++++++++++++++---------------
src/poller/utils.rs | 15 +++++--
4 files changed, 116 insertions(+), 65 deletions(-)
diff --git a/src/app/mod.rs b/src/app/mod.rs
index eadb45d..04aa267 100644
--- a/src/app/mod.rs
+++ b/src/app/mod.rs
@@ -46,7 +46,7 @@ pub async fn spawn_poller_task(db_pool: PgPool) -> JoinHandle<()> {
.expect("[POLLER] Could not find rows in edit rows to start poller");
tokio::spawn(async move {
- if let Err(e) = poller.poll().await {
+ if let Err(e) = poller.run().await {
error!("[POLLER] Task Failed, Error: {}", e);
sentry::capture_error(&e);
}
diff --git a/src/poller/looper.rs b/src/poller/looper.rs
index 1c7e5b2..71a1e99 100644
--- a/src/poller/looper.rs
+++ b/src/poller/looper.rs
@@ -22,6 +22,24 @@ pub async fn poll_db(
edit_note_start_idx, edit_data_start_idx
);
let metrics = Metrics::new().await;
+
+ // Handle Edits
+ let next_edit_id = poll_and_save_edit_data(edit_data_start_idx, pool).await?;
+
+ // Handle Edits Notes
+ let next_edit_note_id = poll_and_save_edit_note_data(edit_note_start_idx, pool).await?;
+
+ // Perf Note: use join! on the two calls
+
+ metrics.db_poll_counter.inc();
+ metrics.push_metrics().await;
+
+ // Return the next ids of the last edit and notes for the next poll
+ Ok((next_edit_id, next_edit_note_id))
+}
+
+/// Poll the edit data from the database and save it
+async fn poll_and_save_edit_data(start_id: i32, pool: &PgPool) -> Result