Archived
fix(jobs): write startup errors to stderr.log
When a job fails to start (e.g., command not found), the error is now written to stderr.log so it appears in `barn describe --logs` output. Previously, the log files were empty for jobs that failed before the process could start, making it hard to diagnose the issue. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
555879be60
commit
e8ea91268a
1 file changed
+10
@@ -1,6 +1,7 @@
|
||||
package com.samsonmedia.barn.execution;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Objects;
|
||||
@@ -164,6 +165,15 @@ public class JobRunner {
|
||||
} catch (IOException e) {
|
||||
LOG.error("Failed to start job {}: {}", job.id(), e.getMessage(), e);
|
||||
|
||||
// Write error to stderr.log so it appears in --logs output
|
||||
try {
|
||||
var stderrFile = dirs.getJobLogsDir(job.id()).resolve(STDERR_LOG);
|
||||
Files.createDirectories(stderrFile.getParent());
|
||||
Files.writeString(stderrFile, "Failed to start process: " + e.getMessage() + "\n");
|
||||
} catch (IOException writeError) {
|
||||
LOG.warn("Failed to write error to stderr.log for job {}: {}", job.id(), writeError.getMessage());
|
||||
}
|
||||
|
||||
if (!completed.get()) {
|
||||
try {
|
||||
repository.markFailed(job.id(), "start_failed", e.getMessage());
|
||||
|
||||
Reference in new issue
Block a user