blob: f1ad40d2aa287d46b6e7e401f20319d0aa65a271 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
use std::sync::Arc;
use anyhow::Result;
use tokio::sync::{
Mutex,
mpsc::{Receiver, Sender},
};
use crate::{
database::Database,
model::{Mail, MailQuery},
};
struct MailProcessor {
rx: Receiver<Mail>,
tx: Sender<Mail>,
db: Arc<Mutex<Database>>,
}
// 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: should this be replaced with a send to another actor to pipeline the work? Is
// the complexity worth the speedup?
match self.do_processing(mail).await {
Ok(_) => todo!(),
Err(_) => todo!(),
}
}
Ok(())
}
async fn do_processing(&mut self, mail: Mail) -> Result<()> {
let mut db_guard = self.db.lock().await;
db_guard.execute(MailQuery::Insert(&mail))?;
drop(db_guard);
todo!();
}
}
mod tests {
// TODO: Think of a way to test
}
|
XMR address: 854DmXNrxULU3ZFJVs4Wc8PFhbq29RhqHhY8W6cdWrtFN3qmooKyyeYPcDzZTNRxphhJ5UzASQfAdEMwSteVqymk28aLhqj