Browse Source
In this first iteration we move saving the event and updating the UI (by sending `CfdChanged` to the projection actor) into the process manager. Next iterations will more the post-processing into the process manager actor step by step until there is not event-related communication with other actors anymore.master^2
Daniel Karzel
3 years ago
5 changed files with 171 additions and 44 deletions
@ -0,0 +1,55 @@ |
|||
use crate::db::append_event; |
|||
use crate::model::cfd; |
|||
use crate::model::cfd::Role; |
|||
use crate::projection; |
|||
use anyhow::Result; |
|||
use xtra::prelude::MessageChannel; |
|||
use xtra_productivity::xtra_productivity; |
|||
|
|||
pub struct Actor { |
|||
db: sqlx::SqlitePool, |
|||
_role: Role, |
|||
cfds_changed: Box<dyn MessageChannel<projection::CfdsChanged>>, |
|||
} |
|||
|
|||
pub struct Event(cfd::Event); |
|||
|
|||
impl Event { |
|||
pub fn new(event: cfd::Event) -> Self { |
|||
Self(event) |
|||
} |
|||
} |
|||
|
|||
impl Actor { |
|||
pub fn new( |
|||
db: sqlx::SqlitePool, |
|||
role: Role, |
|||
cfds_changed: &(impl MessageChannel<projection::CfdsChanged> + 'static), |
|||
) -> Self { |
|||
Self { |
|||
db, |
|||
_role: role, |
|||
cfds_changed: cfds_changed.clone_channel(), |
|||
} |
|||
} |
|||
} |
|||
|
|||
#[xtra_productivity] |
|||
impl Actor { |
|||
fn handle(&mut self, msg: Event) -> Result<()> { |
|||
let event = msg.0; |
|||
|
|||
// 1. Safe in DB
|
|||
let mut conn = self.db.acquire().await?; |
|||
append_event(event.clone(), &mut conn).await?; |
|||
|
|||
// TODO: 2. Post-process event by sending out messages
|
|||
|
|||
// 3. Update UI
|
|||
self.cfds_changed.send(projection::CfdsChanged).await?; |
|||
|
|||
Ok(()) |
|||
} |
|||
} |
|||
|
|||
impl xtra::Actor for Actor {} |
Loading…
Reference in new issue