2025-06-16 18:37:19 -04:00
|
|
|
use async_trait::async_trait;
|
|
|
|
|
use tokio::process::{Child, Command};
|
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
|
|
use crate::executor::{Executor, ExecutorError};
|
|
|
|
|
use crate::models::task::Task;
|
|
|
|
|
|
|
|
|
|
/// A dummy executor that echoes the task title and description
|
|
|
|
|
pub struct EchoExecutor;
|
|
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
|
impl Executor for EchoExecutor {
|
|
|
|
|
fn executor_type(&self) -> &'static str {
|
|
|
|
|
"echo"
|
|
|
|
|
}
|
2025-06-16 18:42:39 -04:00
|
|
|
|
|
|
|
|
async fn spawn(
|
|
|
|
|
&self,
|
|
|
|
|
pool: &sqlx::PgPool,
|
|
|
|
|
task_id: Uuid,
|
|
|
|
|
_worktree_path: &str,
|
|
|
|
|
) -> Result<Child, ExecutorError> {
|
2025-06-16 18:37:19 -04:00
|
|
|
// Get the task to fetch its description
|
|
|
|
|
let task = Task::find_by_id(pool, task_id)
|
|
|
|
|
.await?
|
|
|
|
|
.ok_or(ExecutorError::TaskNotFound)?;
|
2025-06-16 18:42:39 -04:00
|
|
|
|
2025-06-16 18:37:19 -04:00
|
|
|
let message = format!(
|
|
|
|
|
"Executing task: {} - {}",
|
|
|
|
|
task.title,
|
|
|
|
|
task.description.as_deref().unwrap_or("No description")
|
|
|
|
|
);
|
2025-06-16 18:42:39 -04:00
|
|
|
|
2025-06-16 18:37:19 -04:00
|
|
|
let child = Command::new("echo")
|
2025-06-16 18:42:39 -04:00
|
|
|
.kill_on_drop(true)
|
2025-06-16 18:37:19 -04:00
|
|
|
.arg(&message)
|
|
|
|
|
.spawn()
|
|
|
|
|
.map_err(ExecutorError::SpawnFailed)?;
|
2025-06-16 18:42:39 -04:00
|
|
|
|
2025-06-16 18:37:19 -04:00
|
|
|
Ok(child)
|
|
|
|
|
}
|
2025-06-16 18:42:39 -04:00
|
|
|
|
2025-06-16 18:37:19 -04:00
|
|
|
fn description(&self) -> &'static str {
|
|
|
|
|
"Echoes the task title and description"
|
|
|
|
|
}
|
|
|
|
|
}
|