style: cargo fmt --all
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user