This commit is contained in:
parent
ce5d2c9fb4
commit
b9c6c831c1
3 changed files with 36 additions and 12 deletions
|
|
@ -59,6 +59,7 @@ pub async fn execute_agent_run(
|
|||
goal: String,
|
||||
) -> AppResult<TaskResponse> {
|
||||
let run_id = Uuid::new_v4();
|
||||
tracing::info!(%task_id, %run_id, "Starting agent execution run");
|
||||
|
||||
let new_run = task_run::ActiveModel {
|
||||
id: Set(run_id),
|
||||
|
|
@ -81,12 +82,18 @@ pub async fn execute_agent_run(
|
|||
)?;
|
||||
|
||||
let (logs, answer, status) = match agent.run(config).await {
|
||||
Ok((logs, answer)) => (logs, answer, "completed".to_string()),
|
||||
Err(e) => (
|
||||
format!("Execution failed: {}", e),
|
||||
None,
|
||||
"failed".to_string(),
|
||||
),
|
||||
Ok((logs, answer)) => {
|
||||
tracing::info!(%task_id, %run_id, "Agent execution completed successfully");
|
||||
(logs, answer, "completed".to_string())
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!(%task_id, %run_id, error = %e, "Agent execution failed");
|
||||
(
|
||||
format!("Execution failed: {}", e),
|
||||
None,
|
||||
"failed".to_string(),
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
let run: task_run::ActiveModel = TaskRun::find_by_id(run_id)
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ impl Scheduler {
|
|||
.map_err(|e| AppError::Internal(format!("Failed to add job: {}", e)))?;
|
||||
self.tasks_to_jobs.insert(task_id, job_id);
|
||||
|
||||
tracing::info!(%task_id, %cron_expr, "Added task to scheduler");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -71,6 +73,7 @@ impl Scheduler {
|
|||
.remove(&job_id)
|
||||
.await
|
||||
.map_err(|e| AppError::Internal(format!("Failed to remove job: {}", e)))?;
|
||||
tracing::info!(%task_id, "Removed task from scheduler");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -88,6 +91,8 @@ impl Scheduler {
|
|||
|
||||
// Create a new run entry
|
||||
let run_id = Uuid::new_v4();
|
||||
tracing::info!(task_id = %task_id, run_id = %run_id, "Starting scheduled task execution");
|
||||
|
||||
let run = task_run::ActiveModel {
|
||||
id: Set(run_id),
|
||||
task_id: Set(task_id),
|
||||
|
|
@ -109,12 +114,18 @@ impl Scheduler {
|
|||
|
||||
tokio::spawn(async move {
|
||||
let (logs, answer, status) = match agent.run(&config).await {
|
||||
Ok((logs, answer)) => (logs, answer, "completed".to_string()),
|
||||
Err(e) => (
|
||||
format!("Scheduled run failed: {}", e),
|
||||
None,
|
||||
"failed".to_string(),
|
||||
),
|
||||
Ok((logs, answer)) => {
|
||||
tracing::info!(task_id = %task_id, run_id = %run_id, "Scheduled task execution completed successfully");
|
||||
(logs, answer, "completed".to_string())
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!(task_id = %task_id, run_id = %run_id, error = %e, "Scheduled task execution failed");
|
||||
(
|
||||
format!("Scheduled run failed: {}", e),
|
||||
None,
|
||||
"failed".to_string(),
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
let run_complete = task_run::ActiveModel {
|
||||
|
|
|
|||
|
|
@ -68,6 +68,8 @@ pub async fn create_task(
|
|||
}
|
||||
|
||||
let task_id = Uuid::new_v4();
|
||||
tracing::info!(%task_id, goal = %payload.goal, "Creating new task");
|
||||
|
||||
let new_task = crate::entities::task::ActiveModel {
|
||||
id: sea_orm::Set(task_id),
|
||||
goal: sea_orm::Set(payload.goal),
|
||||
|
|
@ -95,6 +97,8 @@ pub async fn rerun_task(
|
|||
.await?
|
||||
.ok_or_else(|| crate::error::AppError::NotFound("Task not found".to_string()))?;
|
||||
|
||||
tracing::info!(task_id = %task.id, "Manually triggering task rerun");
|
||||
|
||||
tasks::execute_agent_run(
|
||||
&state.db,
|
||||
&state.scheduler,
|
||||
|
|
@ -132,6 +136,8 @@ pub async fn update_task(
|
|||
.into();
|
||||
|
||||
let mut task = task;
|
||||
tracing::info!(task_id = %id, goal = %payload.goal, "Updating task");
|
||||
|
||||
task.goal = sea_orm::Set(payload.goal);
|
||||
task.cron = sea_orm::Set(payload.cron.clone());
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue