feat: with domain events
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
c5568f2bea
commit
f9f280278f
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -914,6 +914,8 @@ dependencies = [
|
||||
"mockall",
|
||||
"mockall_double",
|
||||
"prost",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
"tonic",
|
||||
"tonic-build",
|
||||
@ -2016,9 +2018,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.97"
|
||||
version = "1.0.113"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bdf3bf93142acad5821c99197022e170842cdbc1c30482b98750c688c640842a"
|
||||
checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
|
@ -18,6 +18,8 @@ async-trait = "0.1.77"
|
||||
mockall_double = "0.3.1"
|
||||
aws-config = { version = "1.1.5", features = ["behavior-version-latest"] }
|
||||
aws-sdk-s3 = { version = "1.15.0", features = ["behavior-version-latest"] }
|
||||
serde = { version = "1.0.196", features = ["derive"] }
|
||||
serde_json = "1.0.113"
|
||||
|
||||
[build-dependencies]
|
||||
tonic-build = "0.11.0"
|
||||
|
@ -1,2 +1,3 @@
|
||||
mod domain_events;
|
||||
mod file_store;
|
||||
pub mod release_manager;
|
||||
|
24
crates/flux-releaser/src/services/domain_events.rs
Normal file
24
crates/flux-releaser/src/services/domain_events.rs
Normal file
@ -0,0 +1,24 @@
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
|
||||
use super::release_manager::models::ArtifactID;
|
||||
|
||||
pub mod extensions;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DomainEvents {}
|
||||
|
||||
#[cfg(test)]
|
||||
use mockall::{automock, mock, predicate::*};
|
||||
|
||||
#[cfg_attr(test, automock)]
|
||||
impl DomainEvents {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
pub async fn publish_event(&self, event: &str) -> anyhow::Result<()> {
|
||||
tracing::trace!("publish events: {}", event);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
use crate::app::SharedApp;
|
||||
|
||||
#[mockall_double::double]
|
||||
use super::DomainEvents;
|
||||
|
||||
pub trait DomainEventsExt {
|
||||
fn domain_events(&self) -> DomainEvents;
|
||||
}
|
||||
|
||||
impl DomainEventsExt for SharedApp {
|
||||
fn domain_events(&self) -> DomainEvents {
|
||||
DomainEvents::new()
|
||||
}
|
||||
}
|
@ -1,15 +1,24 @@
|
||||
use serde::Serialize;
|
||||
|
||||
#[mockall_double::double]
|
||||
use crate::services::file_store::FileStore;
|
||||
|
||||
#[mockall_double::double]
|
||||
use super::domain_events::DomainEvents;
|
||||
|
||||
use self::models::{ArtifactID, CommitArtifact};
|
||||
|
||||
pub struct ReleaseManager {
|
||||
file_store: FileStore,
|
||||
domain_events: DomainEvents,
|
||||
}
|
||||
|
||||
impl ReleaseManager {
|
||||
pub fn new(file_store: FileStore) -> Self {
|
||||
Self { file_store }
|
||||
pub fn new(file_store: FileStore, domain_events: DomainEvents) -> Self {
|
||||
Self {
|
||||
file_store,
|
||||
domain_events,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn commit_artifact(&self, request: CommitArtifact) -> anyhow::Result<ArtifactID> {
|
||||
@ -20,17 +29,27 @@ impl ReleaseManager {
|
||||
.upload_files(artifact_id.clone(), Vec::new())
|
||||
.await?;
|
||||
|
||||
// publish domain event that it has been published
|
||||
self.domain_events
|
||||
.publish_event(&serde_json::to_string(&CommittedArtifactEvent {
|
||||
artifact_id: artifact_id.to_string(),
|
||||
})?)
|
||||
.await?;
|
||||
|
||||
Ok(artifact_id)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct CommittedArtifactEvent {
|
||||
artifact_id: String,
|
||||
}
|
||||
|
||||
pub mod extensions;
|
||||
pub mod models;
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::services::domain_events::MockDomainEvents;
|
||||
use crate::services::file_store::MockFileStore;
|
||||
|
||||
use super::*;
|
||||
@ -43,7 +62,13 @@ mod test {
|
||||
.times(1)
|
||||
.returning(|_, _| Ok(()));
|
||||
|
||||
let releaser_manager = ReleaseManager::new(file_store);
|
||||
let mut domain_events = MockDomainEvents::default();
|
||||
domain_events
|
||||
.expect_publish_event()
|
||||
.times(1)
|
||||
.returning(|_| Ok(()));
|
||||
|
||||
let releaser_manager = ReleaseManager::new(file_store, domain_events);
|
||||
|
||||
releaser_manager
|
||||
.commit_artifact(CommitArtifact {
|
||||
|
@ -1,4 +1,7 @@
|
||||
use crate::{app::SharedApp, services::file_store::extensions::FileStoreExt};
|
||||
use crate::{
|
||||
app::SharedApp,
|
||||
services::{domain_events::extensions::DomainEventsExt, file_store::extensions::FileStoreExt},
|
||||
};
|
||||
|
||||
use super::ReleaseManager;
|
||||
|
||||
@ -8,6 +11,6 @@ pub trait ReleaseManagerExt {
|
||||
|
||||
impl ReleaseManagerExt for SharedApp {
|
||||
fn release_manager(&self) -> ReleaseManager {
|
||||
ReleaseManager::new(self.file_store())
|
||||
ReleaseManager::new(self.file_store(), self.domain_events())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user