Capture logs from setup script

This commit is contained in:
Louis Knight-Webb
2025-06-20 23:12:16 +01:00
parent 218b611901
commit cc46e40a17
2 changed files with 31 additions and 2 deletions

View File

@@ -111,7 +111,7 @@ impl ExecutorConfig {
}
/// Stream output from a child process to the database
async fn stream_output_to_db(
pub async fn stream_output_to_db(
output: impl tokio::io::AsyncRead + Unpin,
pool: sqlx::SqlitePool,
attempt_id: Uuid,

View File

@@ -456,7 +456,7 @@ impl TaskAttempt {
tracing::info!("Running setup script for task attempt {}", attempt_id);
// Start setup script as streaming process
let child = tokio::process::Command::new("bash")
let mut child = tokio::process::Command::new("bash")
.arg("-c")
.arg(setup_script)
.current_dir(&task_attempt.worktree_path)
@@ -470,6 +470,35 @@ impl TaskAttempt {
)))
})?;
// Stream stdout and stderr to database
if let Some(stdout) = child.stdout.take() {
let pool_clone = pool.clone();
tokio::spawn(async move {
crate::executor::stream_output_to_db(
stdout,
pool_clone,
attempt_id,
setup_process_id,
true,
)
.await;
});
}
if let Some(stderr) = child.stderr.take() {
let pool_clone = pool.clone();
tokio::spawn(async move {
crate::executor::stream_output_to_db(
stderr,
pool_clone,
attempt_id,
setup_process_id,
false,
)
.await;
});
}
// Add setup script to running executions for monitoring
app_state
.add_running_execution(