style: cargo fmt --all

This commit is contained in:
2026-05-31 05:31:42 +02:00
parent 4b31a0f74b
commit c2ebca0da0
138 changed files with 2422 additions and 1164 deletions

View File

@@ -1,4 +1,3 @@
use std::sync::Arc;
use domain::{
entities::Job,
errors::DomainError,
@@ -6,6 +5,7 @@ use domain::{
ports::{EventPublisher, JobBatchRepository, JobRepository},
value_objects::{DateTimeStamp, StructuredData, SystemId},
};
use std::sync::Arc;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct CompleteJobCommand {
@@ -25,24 +25,35 @@ impl CompleteJobHandler {
batch_repo: Arc<dyn JobBatchRepository>,
event_pub: Arc<dyn EventPublisher>,
) -> Self {
Self { job_repo, batch_repo, event_pub }
Self {
job_repo,
batch_repo,
event_pub,
}
}
pub async fn execute(&self, cmd: CompleteJobCommand) -> Result<Job, DomainError> {
let mut job = self.job_repo.find_by_id(&cmd.job_id).await?
let mut job = self
.job_repo
.find_by_id(&cmd.job_id)
.await?
.ok_or_else(|| DomainError::NotFound(format!("Job {} not found", cmd.job_id)))?;
job.complete(cmd.result);
self.job_repo.save(&job).await?;
if let Some(ref batch_id) = job.batch_id {
let mut batch = self.batch_repo.find_by_id(batch_id).await?
.ok_or_else(|| DomainError::NotFound(format!("Batch {} not found", batch_id)))?;
let mut batch =
self.batch_repo.find_by_id(batch_id).await?.ok_or_else(|| {
DomainError::NotFound(format!("Batch {} not found", batch_id))
})?;
batch.record_completion();
self.batch_repo.save(&batch).await?;
}
self.event_pub.publish(DomainEvent::JobCompleted {
job_id: job.job_id,
timestamp: DateTimeStamp::now(),
}).await?;
self.event_pub
.publish(DomainEvent::JobCompleted {
job_id: job.job_id,
timestamp: DateTimeStamp::now(),
})
.await?;
Ok(job)
}
}

View File

@@ -1,10 +1,10 @@
use std::sync::Arc;
use domain::{
entities::ProcessingPipeline,
errors::DomainError,
ports::{PipelineRepository, PluginRepository},
value_objects::{StructuredData, SystemId},
};
use std::sync::Arc;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct PipelineStepConfig {
@@ -28,13 +28,23 @@ impl ConfigurePipelineHandler {
pipeline_repo: Arc<dyn PipelineRepository>,
plugin_repo: Arc<dyn PluginRepository>,
) -> Self {
Self { pipeline_repo, plugin_repo }
Self {
pipeline_repo,
plugin_repo,
}
}
pub async fn execute(&self, cmd: ConfigurePipelineCommand) -> Result<ProcessingPipeline, DomainError> {
pub async fn execute(
&self,
cmd: ConfigurePipelineCommand,
) -> Result<ProcessingPipeline, DomainError> {
for step in &cmd.steps {
self.plugin_repo.find_by_id(&step.plugin_id).await?
.ok_or_else(|| DomainError::NotFound(format!("Plugin {} not found", step.plugin_id)))?;
self.plugin_repo
.find_by_id(&step.plugin_id)
.await?
.ok_or_else(|| {
DomainError::NotFound(format!("Plugin {} not found", step.plugin_id))
})?;
}
let mut pipeline = ProcessingPipeline::new(cmd.trigger_event);
for step in cmd.steps {

View File

@@ -1,4 +1,3 @@
use std::sync::Arc;
use domain::{
entities::{Job, JobType},
errors::DomainError,
@@ -6,6 +5,7 @@ use domain::{
ports::{EventPublisher, JobRepository},
value_objects::{DateTimeStamp, StructuredData, SystemId},
};
use std::sync::Arc;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct EnqueueJobCommand {
@@ -23,7 +23,10 @@ pub struct EnqueueJobHandler {
impl EnqueueJobHandler {
pub fn new(job_repo: Arc<dyn JobRepository>, event_pub: Arc<dyn EventPublisher>) -> Self {
Self { job_repo, event_pub }
Self {
job_repo,
event_pub,
}
}
pub async fn execute(&self, cmd: EnqueueJobCommand) -> Result<Job, DomainError> {
@@ -35,11 +38,13 @@ impl EnqueueJobHandler {
job = job.with_batch(id);
}
self.job_repo.save(&job).await?;
self.event_pub.publish(DomainEvent::JobEnqueued {
job_id: job.job_id,
job_type: format!("{:?}", cmd.job_type),
timestamp: DateTimeStamp::now(),
}).await?;
self.event_pub
.publish(DomainEvent::JobEnqueued {
job_id: job.job_id,
job_type: format!("{:?}", cmd.job_type),
timestamp: DateTimeStamp::now(),
})
.await?;
Ok(job)
}
}

View File

@@ -1,4 +1,3 @@
use std::sync::Arc;
use domain::{
entities::{Job, JobStatus},
errors::DomainError,
@@ -6,6 +5,7 @@ use domain::{
ports::{EventPublisher, JobBatchRepository, JobRepository},
value_objects::{DateTimeStamp, SystemId},
};
use std::sync::Arc;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct FailJobCommand {
@@ -25,32 +25,44 @@ impl FailJobHandler {
batch_repo: Arc<dyn JobBatchRepository>,
event_pub: Arc<dyn EventPublisher>,
) -> Self {
Self { job_repo, batch_repo, event_pub }
Self {
job_repo,
batch_repo,
event_pub,
}
}
pub async fn execute(&self, cmd: FailJobCommand) -> Result<Job, DomainError> {
let mut job = self.job_repo.find_by_id(&cmd.job_id).await?
let mut job = self
.job_repo
.find_by_id(&cmd.job_id)
.await?
.ok_or_else(|| DomainError::NotFound(format!("Job {} not found", cmd.job_id)))?;
job.fail(&cmd.error);
self.job_repo.save(&job).await?;
if job.status == JobStatus::Failed {
if let Some(ref batch_id) = job.batch_id {
let mut batch = self.batch_repo.find_by_id(batch_id).await?
.ok_or_else(|| DomainError::NotFound(format!("Batch {} not found", batch_id)))?;
let mut batch = self.batch_repo.find_by_id(batch_id).await?.ok_or_else(|| {
DomainError::NotFound(format!("Batch {} not found", batch_id))
})?;
batch.record_failure();
self.batch_repo.save(&batch).await?;
}
self.event_pub.publish(DomainEvent::JobFailed {
job_id: job.job_id,
error: cmd.error,
timestamp: DateTimeStamp::now(),
}).await?;
self.event_pub
.publish(DomainEvent::JobFailed {
job_id: job.job_id,
error: cmd.error,
timestamp: DateTimeStamp::now(),
})
.await?;
} else if job.status == JobStatus::Queued {
self.event_pub.publish(DomainEvent::JobEnqueued {
job_id: job.job_id,
job_type: format!("{:?}", job.job_type),
timestamp: DateTimeStamp::now(),
}).await?;
self.event_pub
.publish(DomainEvent::JobEnqueued {
job_id: job.job_id,
job_type: format!("{:?}", job.job_type),
timestamp: DateTimeStamp::now(),
})
.await?;
}
Ok(job)
}

View File

@@ -1,10 +1,10 @@
use std::sync::Arc;
use domain::{
entities::{Plugin, PluginType},
errors::DomainError,
ports::PluginRepository,
value_objects::{StructuredData, SystemId},
};
use std::sync::Arc;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum PluginAction {
@@ -34,25 +34,37 @@ impl ManagePluginHandler {
pub async fn execute(&self, cmd: ManagePluginCommand) -> Result<Plugin, DomainError> {
match cmd.action {
PluginAction::Create { name, plugin_type, config } => {
PluginAction::Create {
name,
plugin_type,
config,
} => {
let mut plugin = Plugin::new(name, plugin_type);
plugin.configuration = config;
self.plugin_repo.save(&plugin).await?;
Ok(plugin)
}
PluginAction::Enable => {
let id = cmd.plugin_id
.ok_or_else(|| DomainError::Validation("plugin_id required for Enable".into()))?;
let mut plugin = self.plugin_repo.find_by_id(&id).await?
let id = cmd.plugin_id.ok_or_else(|| {
DomainError::Validation("plugin_id required for Enable".into())
})?;
let mut plugin = self
.plugin_repo
.find_by_id(&id)
.await?
.ok_or_else(|| DomainError::NotFound(format!("Plugin {} not found", id)))?;
plugin.enable();
self.plugin_repo.save(&plugin).await?;
Ok(plugin)
}
PluginAction::Disable => {
let id = cmd.plugin_id
.ok_or_else(|| DomainError::Validation("plugin_id required for Disable".into()))?;
let mut plugin = self.plugin_repo.find_by_id(&id).await?
let id = cmd.plugin_id.ok_or_else(|| {
DomainError::Validation("plugin_id required for Disable".into())
})?;
let mut plugin = self
.plugin_repo
.find_by_id(&id)
.await?
.ok_or_else(|| DomainError::NotFound(format!("Plugin {} not found", id)))?;
plugin.disable();
self.plugin_repo.save(&plugin).await?;

View File

@@ -1,6 +1,6 @@
pub mod enqueue_job;
pub mod start_job;
pub mod complete_job;
pub mod configure_pipeline;
pub mod enqueue_job;
pub mod fail_job;
pub mod manage_plugin;
pub mod configure_pipeline;
pub mod start_job;

View File

@@ -1,10 +1,5 @@
use domain::{entities::Job, errors::DomainError, ports::JobRepository, value_objects::SystemId};
use std::sync::Arc;
use domain::{
entities::Job,
errors::DomainError,
ports::JobRepository,
value_objects::SystemId,
};
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct StartJobCommand {
@@ -21,7 +16,10 @@ impl StartJobHandler {
}
pub async fn execute(&self, cmd: StartJobCommand) -> Result<Job, DomainError> {
let mut job = self.job_repo.find_by_id(&cmd.job_id).await?
let mut job = self
.job_repo
.find_by_id(&cmd.job_id)
.await?
.ok_or_else(|| DomainError::NotFound(format!("Job {} not found", cmd.job_id)))?;
job.start()?;
self.job_repo.save(&job).await?;

View File

@@ -1,10 +1,14 @@
pub mod commands;
pub mod queries;
pub use commands::enqueue_job::{EnqueueJobCommand, EnqueueJobHandler};
pub use commands::start_job::{StartJobCommand, StartJobHandler};
pub use commands::complete_job::{CompleteJobCommand, CompleteJobHandler};
pub use commands::configure_pipeline::{
ConfigurePipelineCommand, ConfigurePipelineHandler, PipelineStepConfig,
};
pub use commands::enqueue_job::{EnqueueJobCommand, EnqueueJobHandler};
pub use commands::fail_job::{FailJobCommand, FailJobHandler};
pub use commands::manage_plugin::{ManagePluginCommand, ManagePluginHandler, PluginAction};
pub use commands::configure_pipeline::{ConfigurePipelineCommand, ConfigurePipelineHandler, PipelineStepConfig};
pub use queries::report_batch_progress::{ReportBatchProgressQuery, ReportBatchProgressHandler, BatchProgress};
pub use commands::start_job::{StartJobCommand, StartJobHandler};
pub use queries::report_batch_progress::{
BatchProgress, ReportBatchProgressHandler, ReportBatchProgressQuery,
};

View File

@@ -1,10 +1,10 @@
use std::sync::Arc;
use domain::{
entities::{Job, JobBatch},
errors::DomainError,
ports::{JobBatchRepository, JobRepository},
value_objects::SystemId,
};
use std::sync::Arc;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ReportBatchProgressQuery {
@@ -24,11 +24,20 @@ pub struct ReportBatchProgressHandler {
impl ReportBatchProgressHandler {
pub fn new(batch_repo: Arc<dyn JobBatchRepository>, job_repo: Arc<dyn JobRepository>) -> Self {
Self { batch_repo, job_repo }
Self {
batch_repo,
job_repo,
}
}
pub async fn execute(&self, query: ReportBatchProgressQuery) -> Result<BatchProgress, DomainError> {
let batch = self.batch_repo.find_by_id(&query.batch_id).await?
pub async fn execute(
&self,
query: ReportBatchProgressQuery,
) -> Result<BatchProgress, DomainError> {
let batch = self
.batch_repo
.find_by_id(&query.batch_id)
.await?
.ok_or_else(|| DomainError::NotFound(format!("Batch {} not found", query.batch_id)))?;
let jobs = self.job_repo.find_by_batch(&query.batch_id).await?;
Ok(BatchProgress { batch, jobs })