websockets
This commit is contained in:
parent
b44e4ed6f9
commit
f0b53b67ce
9 changed files with 268 additions and 28 deletions
|
|
@ -22,7 +22,7 @@ pub struct UpdateTaskRequest {
|
|||
pub cron: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[derive(Serialize, Clone, Debug)]
|
||||
pub struct TaskResponse {
|
||||
pub id: Uuid,
|
||||
pub goal: String,
|
||||
|
|
@ -31,7 +31,7 @@ pub struct TaskResponse {
|
|||
pub runs: Vec<TaskRunResponse>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[derive(Serialize, Clone, Debug)]
|
||||
pub struct TaskRunResponse {
|
||||
pub id: Uuid,
|
||||
pub status: String,
|
||||
|
|
@ -40,7 +40,7 @@ pub struct TaskRunResponse {
|
|||
pub created_at: chrono::DateTime<chrono::FixedOffset>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[derive(Serialize, Clone, Debug)]
|
||||
pub struct RecentRunResponse {
|
||||
pub id: Uuid,
|
||||
pub task_id: Uuid,
|
||||
|
|
@ -75,6 +75,18 @@ pub async fn execute_agent_run(
|
|||
.await
|
||||
.map_err(crate::error::AppError::Database)?;
|
||||
|
||||
let _ = _scheduler
|
||||
.tx
|
||||
.send(crate::server::notifications::WsEvent::RunStarted(
|
||||
RecentRunResponse {
|
||||
id: run_id,
|
||||
task_id,
|
||||
goal: goal.clone(),
|
||||
status: "running".to_string(),
|
||||
created_at: Utc::now().into(),
|
||||
},
|
||||
));
|
||||
|
||||
let mut agent = Agent::new(
|
||||
db.clone(),
|
||||
config.zen_api_key.clone(),
|
||||
|
|
@ -113,7 +125,14 @@ pub async fn execute_agent_run(
|
|||
.await
|
||||
.map_err(crate::error::AppError::Database)?;
|
||||
|
||||
get_task_inner(task_id, db).await
|
||||
let task_response = get_task_inner(task_id, db).await?;
|
||||
let _ = _scheduler
|
||||
.tx
|
||||
.send(crate::server::notifications::WsEvent::RunFinished(
|
||||
task_response.clone(),
|
||||
));
|
||||
|
||||
Ok(task_response)
|
||||
}
|
||||
|
||||
pub async fn get_task_inner(id: Uuid, db: &DatabaseConnection) -> AppResult<TaskResponse> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue