code refactor
Some checks failed
CI / Check / Test (push) Has been cancelled

Reviewed-on: #26
This commit was merged in pull request #26.
This commit is contained in:
2026-10-26 09:36:23 +00:00
parent 2ce7db12c2
commit 017b58d6fa
804 changed files with 33423 additions and 28955 deletions

View File

@@ -1,10 +1,14 @@
[package]
name = "event-publisher"
version = "0.1.0"
edition = "2024"
edition.workspace = true
[dependencies]
config = { workspace = true }
domain = { workspace = true }
async-trait = { workspace = true }
tokio = { workspace = true }
tokio = { workspace = true, features = ["sync"] }
futures = { workspace = true }
[dev-dependencies]
tokio = { workspace = true, features = ["rt", "macros"] }

View File

@@ -16,12 +16,10 @@ pub struct EventPublisherConfig {
}
impl EventPublisherConfig {
pub fn from_env() -> Self {
let channel_buffer = std::env::var("EVENT_CHANNEL_BUFFER")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(128);
Self { channel_buffer }
pub fn from_config(config: &config::EventsConfig) -> Self {
Self {
channel_buffer: config.channel_buffer,
}
}
}
@@ -49,6 +47,9 @@ impl AckHandle for NoopAck {
async fn nack(&self) -> Result<(), DomainError> {
Ok(())
}
async fn defer(&self, _: std::time::Duration) -> Result<(), DomainError> {
Ok(())
}
}
pub struct ChannelEventConsumer {
@@ -60,7 +61,7 @@ impl EventConsumer for ChannelEventConsumer {
let receiver = Arc::clone(&self.receiver);
Box::pin(stream::unfold(receiver, |rx| async move {
let event = rx.lock().await.recv().await?;
let envelope = EventEnvelope::new(event, Box::new(NoopAck));
let envelope = EventEnvelope::new(None, event, Box::new(NoopAck));
Some((Ok(envelope), rx))
}))
}
@@ -86,7 +87,3 @@ pub fn create_event_channel(
},
)
}
#[cfg(test)]
#[path = "tests/lib.rs"]
mod tests;

View File

@@ -1,8 +1,9 @@
use super::*;
use domain::ports::{EventConsumer, EventPublisher};
use domain::{
events::DomainEvent,
value_objects::{ExternalMetadataId, MovieId},
};
use event_publisher::{EventPublisherConfig, create_event_channel};
use futures::StreamExt;
fn movie_discovered() -> DomainEvent {