From b336fd39444e8089d35a7a2bd4c0c3e8228c6c36 Mon Sep 17 00:00:00 2001 From: Mroik Date: Fri, 10 Apr 2026 00:21:25 +0200 Subject: Add mail processing scaffolding After receiving the email we don't want to process it in the same thread as soon as we can, instead we queue it to a MailProcessor. This allows us to be more flexible with the pipeline and reduce the amount of concurrency for the database connection. This also helps with writing possible fences around resource consumption. Signed-off-by: Mroik --- src/process_mail.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/process_mail.rs (limited to 'src/process_mail.rs') diff --git a/src/process_mail.rs b/src/process_mail.rs new file mode 100644 index 0000000..5a22ce1 --- /dev/null +++ b/src/process_mail.rs @@ -0,0 +1,23 @@ +use anyhow::Result; +use tokio::sync::mpsc::{Receiver, Sender}; + +use crate::model::Mail; + +struct MailProcessor { + rx: Receiver, + tx: Sender, +} + +// TODO: Store first then forward. On complete forward remove from db, otherwise save db with the +// emails to send to. +impl MailProcessor { + async fn run(&mut self) -> Result<()> { + // TODO: Check againts self.rx.is_closed() instead to stop the program before consuming all + // of the queue. Store the emails not yet processed and restore the queue upon startup. + while let Some(mail) = self.rx.recv().await { + todo!() + } + + Ok(()) + } +} -- cgit v1.3