feat(cli): add retry columns to barn status output

Surface retryCount and retryAt fields in the human table format for
barn status, so retrying jobs are distinguishable from freshly queued
jobs. Also add retryAt to the single job detail view.

- Add RETRIES and NEXT RETRY columns to StatusCommand and HumanFormatter
- Add retryAt display to HumanFormatter single job detail
- Update README and testing-manual docs with new columns
- Add tests for retry display in StatusCommand, HumanFormatter, and XmlFormatter

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Daniel SamsonandClaude Opus 4.6 committed 2026-03-03 19:40:43 +00:00
1 parent 14bb82fc9d
commit b53b4a3287
7 files changed
+123 -10

No files matched your search

@@ -135,12 +135,17 @@ public class HumanFormatter implements OutputFormatter {
sb.append(" Retries: ").append(job.retryCount()).append("\n");
}
if (job.retryAt() != null) {
sb.append(" Retry At: ").append(formatTimestamp(job.retryAt())).append("\n");
}
return sb.toString().trim();
}
private String formatJobTable(List<Job> jobs) {
// Define columns
List<String> headers = List.of("ID", "STATE", "LOAD", "TAG", "CREATED", "EXIT");
List<String> headers = List.of(
"ID", "STATE", "LOAD", "TAG", "CREATED", "EXIT", "RETRIES", "NEXT RETRY");
// Convert jobs to rows
List<List<String>> rows = new ArrayList<>();
@@ -151,7 +156,9 @@ public class HumanFormatter implements OutputFormatter {
job.loadLevel().toString().toLowerCase(Locale.ROOT),
job.tag() != null ? job.tag() : "-",
formatTimestamp(job.createdAt()),
job.exitCode() != null ? job.exitCode().toString() : "-"
job.exitCode() != null ? job.exitCode().toString() : "-",
job.retryCount() > 0 ? String.valueOf(job.retryCount()) : "-",
job.retryAt() != null ? formatTimestamp(job.retryAt()) : "-"
));
}
@@ -195,19 +195,23 @@ public class StatusCommand extends BaseCommand {
.max().orElse(3));
// Header
sb.append(String.format("%-" + idWidth + "s %-9s %-6s %-" + tagWidth + "s %-19s %-4s %-8s%n",
"ID", "STATE", "LOAD", "TAG", "CREATED", "EXIT", "PID"));
sb.append(String.format(
"%-" + idWidth + "s %-9s %-6s %-" + tagWidth + "s %-19s %-4s %-8s %-7s %-19s%n",
"ID", "STATE", "LOAD", "TAG", "CREATED", "EXIT", "PID", "RETRIES", "NEXT RETRY"));
// Rows
for (Job job : jobs) {
sb.append(String.format("%-" + idWidth + "s %-9s %-6s %-" + tagWidth + "s %-19s %-4s %-8s%n",
sb.append(String.format(
"%-" + idWidth + "s %-9s %-6s %-" + tagWidth + "s %-19s %-4s %-8s %-7s %-19s%n",
job.id(),
job.state().toString().toLowerCase(Locale.ROOT),
job.loadLevel().toString().toLowerCase(Locale.ROOT),
job.tag() != null ? job.tag() : "-",
formatTimestamp(job.createdAt()),
job.exitCode() != null ? job.exitCode().toString() : "-",
job.pid() != null ? job.pid().toString() : "-"));
job.pid() != null ? job.pid().toString() : "-",
job.retryCount() > 0 ? String.valueOf(job.retryCount()) : "-",
job.retryAt() != null ? formatTimestamp(job.retryAt()) : "-"));
}
// Summary
@@ -79,6 +79,18 @@ class HumanFormatterTest {
assertThat(result).contains("Process failed");
}
@Test
void format_withRetryingJob_shouldShowRetryInfo() {
Job job = createRetryingJob("job-retry1234", 3,
Instant.parse("2026-01-15T10:30:00Z"));
String result = formatter.format(job);
assertThat(result).contains("Retries:");
assertThat(result).contains("3");
assertThat(result).contains("Retry At:");
}
@Test
void format_withMap_shouldFormatKeyValues() {
Map<String, Object> map = new LinkedHashMap<>();
@@ -127,6 +139,18 @@ class HumanFormatterTest {
assertThat(result).contains("medium");
}
@Test
void formatList_withRetryingJob_shouldShowRetryColumns() {
List<Job> jobs = List.of(createRetryingJob("job-retry1234", 2,
Instant.parse("2026-01-15T10:30:00Z")));
String result = formatter.formatList(jobs);
assertThat(result).contains("RETRIES");
assertThat(result).contains("NEXT RETRY");
assertThat(result).contains("2");
}
@Test
void formatList_withStrings_shouldFormatEach() {
List<String> strings = List.of("item1", "item2", "item3");
@@ -242,4 +266,23 @@ class HumanFormatterTest {
MEDIUM
);
}
private Job createRetryingJob(String id, int retryCount, Instant retryAt) {
return new Job(
id,
JobState.QUEUED,
List.of("echo", "test"),
"tag",
Instant.now().minus(Duration.ofMinutes(5)),
null,
null,
null,
null,
null,
null,
retryCount,
retryAt,
MEDIUM
);
}
}
@@ -6,6 +6,8 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.Path;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
@@ -14,6 +16,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import com.samsonmedia.barn.config.JobsConfig;
import com.samsonmedia.barn.jobs.Job;
import com.samsonmedia.barn.jobs.JobRepository;
import com.samsonmedia.barn.state.BarnDirectories;
@@ -100,6 +103,22 @@ class StatusCommandTest {
assertThat(exitCode).isZero();
assertThat(stdout.toString().toLowerCase()).contains("queued");
}
@Test
void status_withRetryingJob_shouldShowRetryColumns() throws IOException {
Job job = repository.create(List.of("echo", "test"), "test", config);
repository.markStarted(job.id(), 12345L);
repository.markCompleted(job.id(), 1, "test failure");
Instant retryAt = Instant.now().plus(5, ChronoUnit.MINUTES);
repository.scheduleRetry(job.id(), retryAt);
int exitCode = cmd.execute("--offline");
assertThat(exitCode).isZero();
String output = stdout.toString();
assertThat(output).contains("RETRIES");
assertThat(output).contains("NEXT RETRY");
}
}
@Nested
@@ -192,8 +192,44 @@ class XmlFormatterTest {
}
}
@Nested
class RetryFields {
@Test
void format_withRetryingJob_shouldIncludeRetryFields() {
Job job = createRetryingJob("job-retry1234", 2,
Instant.parse("2026-01-15T10:30:00Z"));
String result = formatter.format(job);
assertThat(result).contains("<retry_count>2</retry_count>");
assertThat(result).contains("<retry_at>");
assertThat(result).contains("2026-01-15T10:30:00Z");
assertThat(result).contains("</retry_at>");
}
}
// Helper methods
private Job createRetryingJob(String id, int retryCount, Instant retryAt) {
return new Job(
id,
JobState.QUEUED,
List.of("echo", "test"),
"tag",
Instant.now(),
null,
null,
null,
null,
null,
null,
retryCount,
retryAt,
MEDIUM
);
}
private Job createJob(String id, JobState state, String tag) {
return new Job(
id,