background worker

This commit is contained in:
2026-05-10 11:12:52 +02:00
parent c8fe4a77d1
commit 3342905e22
15 changed files with 585 additions and 174 deletions

View File

@@ -1,6 +1,10 @@
use async_trait::async_trait;
use chrono::NaiveDateTime;
use crate::value_objects::{ExternalMetadataId, MovieId, Rating, ReviewId, UserId};
use crate::{
errors::DomainError,
value_objects::{ExternalMetadataId, MovieId, Rating, ReviewId, UserId},
};
#[derive(Clone, Debug)]
pub enum DomainEvent {
@@ -23,3 +27,28 @@ pub enum DomainEvent {
external_metadata_id: ExternalMetadataId,
},
}
#[async_trait]
pub trait AckHandle: Send + Sync {
async fn ack(&self) -> Result<(), DomainError>;
async fn nack(&self) -> Result<(), DomainError>;
}
pub struct EventEnvelope {
pub event: DomainEvent,
ack: Box<dyn AckHandle>,
}
impl EventEnvelope {
pub fn new(event: DomainEvent, ack: Box<dyn AckHandle>) -> Self {
Self { event, ack }
}
pub async fn ack(self) -> Result<(), DomainError> {
self.ack.ack().await
}
pub async fn nack(self) -> Result<(), DomainError> {
self.ack.nack().await
}
}