feat(sdk,plugins): API publique d'accès fichiers/workspace + analyse structure (#124,#129)
This commit is contained in:
@ -17,11 +17,12 @@ use std::sync::Arc;
|
||||
|
||||
use domain::ports::{
|
||||
BackgroundTaskPortError, BackgroundTaskRunner, BackgroundTaskSpec, BackgroundTaskStore, Clock,
|
||||
IdGenerator, SpawnSpec,
|
||||
EventBus, IdGenerator, SpawnSpec,
|
||||
};
|
||||
use domain::{
|
||||
AgentId, BackgroundTask, BackgroundTaskKind, BackgroundTaskRendezvousLink,
|
||||
BackgroundTaskResult, BackgroundTaskState, BackgroundTaskWakePolicy, ProjectId, TaskId,
|
||||
BackgroundTaskResult, BackgroundTaskState, BackgroundTaskWakePolicy, DomainEvent, ProjectId,
|
||||
TaskId,
|
||||
};
|
||||
|
||||
use crate::error::AppError;
|
||||
@ -71,6 +72,7 @@ pub struct SpawnBackgroundCommand {
|
||||
runner: Arc<dyn BackgroundTaskRunner>,
|
||||
clock: Arc<dyn Clock>,
|
||||
ids: Arc<dyn IdGenerator>,
|
||||
events: Option<Arc<dyn EventBus>>,
|
||||
}
|
||||
|
||||
impl SpawnBackgroundCommand {
|
||||
@ -87,9 +89,17 @@ impl SpawnBackgroundCommand {
|
||||
runner,
|
||||
clock,
|
||||
ids,
|
||||
events: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Attaches the public event stream publisher.
|
||||
#[must_use]
|
||||
pub fn with_events(mut self, events: Arc<dyn EventBus>) -> Self {
|
||||
self.events = Some(events);
|
||||
self
|
||||
}
|
||||
|
||||
/// Allocates a task id, persists it (`Queued`→`Running`) and spawns it.
|
||||
///
|
||||
/// # Errors
|
||||
@ -145,6 +155,19 @@ impl SpawnBackgroundCommand {
|
||||
.transition(BackgroundTaskState::Running, now)
|
||||
.map_err(|e| AppError::Invalid(e.to_string()))?;
|
||||
self.store.save(&running).await.map_err(map_port_err)?;
|
||||
if let Some(events) = &self.events {
|
||||
events.publish(DomainEvent::BackgroundTaskStarted {
|
||||
project_id,
|
||||
task_id,
|
||||
owner_agent_id,
|
||||
});
|
||||
events.publish(DomainEvent::BackgroundTaskStateChanged {
|
||||
project_id,
|
||||
task_id,
|
||||
owner_agent_id,
|
||||
state: BackgroundTaskState::Running,
|
||||
});
|
||||
}
|
||||
|
||||
let spec = BackgroundTaskSpec {
|
||||
task_id,
|
||||
@ -168,6 +191,14 @@ impl SpawnBackgroundCommand {
|
||||
}) {
|
||||
let _ = self.store.save(&failed).await;
|
||||
}
|
||||
if let Some(events) = &self.events {
|
||||
events.publish(DomainEvent::BackgroundTaskFailed {
|
||||
project_id,
|
||||
task_id,
|
||||
owner_agent_id,
|
||||
rendezvous: None,
|
||||
});
|
||||
}
|
||||
return Err(map_port_err(err));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user