app: add sidecar sync commands (export, detect, import, resolve, full export/import)

This commit is contained in:
2026-05-31 05:29:03 +02:00
parent d1394ce7bb
commit 4b31a0f74b
43 changed files with 1685 additions and 6 deletions

View File

@@ -0,0 +1,48 @@
use std::sync::Arc;
use domain::{
entities::Job,
errors::DomainError,
events::DomainEvent,
ports::{EventPublisher, JobBatchRepository, JobRepository},
value_objects::{DateTimeStamp, StructuredData, SystemId},
};
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct CompleteJobCommand {
pub job_id: SystemId,
pub result: StructuredData,
}
pub struct CompleteJobHandler {
job_repo: Arc<dyn JobRepository>,
batch_repo: Arc<dyn JobBatchRepository>,
event_pub: Arc<dyn EventPublisher>,
}
impl CompleteJobHandler {
pub fn new(
job_repo: Arc<dyn JobRepository>,
batch_repo: Arc<dyn JobBatchRepository>,
event_pub: Arc<dyn EventPublisher>,
) -> Self {
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?
.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)))?;
batch.record_completion();
self.batch_repo.save(&batch).await?;
}
self.event_pub.publish(DomainEvent::JobCompleted {
job_id: job.job_id,
timestamp: DateTimeStamp::now(),
}).await?;
Ok(job)
}
}