From b9c6c831c1276e0f421248d7fee77f2f7bb4419d Mon Sep 17 00:00:00 2001 From: pavel Date: Wed, 11 Feb 2026 01:55:13 +0100 Subject: [PATCH] improve logging --- src/domain/tasks.rs | 19 +++++++++++++------ src/scheduler.rs | 23 +++++++++++++++++------ src/server/tasks.rs | 6 ++++++ 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/domain/tasks.rs b/src/domain/tasks.rs index 0968cdf..5092091 100644 --- a/src/domain/tasks.rs +++ b/src/domain/tasks.rs @@ -59,6 +59,7 @@ pub async fn execute_agent_run( goal: String, ) -> AppResult { 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) diff --git a/src/scheduler.rs b/src/scheduler.rs index b7d3996..2ee8a01 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -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 { diff --git a/src/server/tasks.rs b/src/server/tasks.rs index 963632b..9782b9c 100644 --- a/src/server/tasks.rs +++ b/src/server/tasks.rs @@ -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());