Implement 'barn describe' command #11

Closed
opened 2026-10-04 19:28:08 +00:00 by daniel · 1 comment
Owner

Imported from GitHub samson-media/barn#11 — opened by @daniel-samson on 2026-01-21 12:39:06 UTC

Overview

Implement the barn describe command that shows detailed information about a specific job.

Context

  • Read first: README.md (barn describe examples), docs/jobs.md (job directory layout)
  • Depends on: #8 (CLI framework), #4 (job model)

Requirements

1. Describe Command

com.samsonmedia.barn.cli.DescribeCommand.java:

@Command(name = "describe", description = "Show detailed job information")
public class DescribeCommand extends BaseCommand {
    @Parameters(index = "0", description = "Job ID")
    private String jobId;

    @Option(names = {"--logs"}, description = "Include log file contents")
    private boolean includeLogs;

    @Option(names = {"--manifest"}, description = "Show full manifest")
    private boolean showManifest;

    @Override
    public Integer call() {
        // 1. Load job by ID
        // 2. Format detailed output
        // 3. Optionally include logs
    }
}

2. Usage Examples

# Basic describe
barn describe job-9f83c

# Include logs
barn describe job-9f83c --logs

# Show manifest
barn describe job-9f83c --manifest

# JSON output
barn describe job-9f83c --output=json

3. Human-Readable Output

Job: job-9f83c
================================================================================
State:      running
Tag:        transcode
Command:    ffmpeg -i input.mp4 -c:v libx264 output.mp4

Timestamps:
  Created:  2026-01-21 18:40:01
  Started:  2026-01-21 18:40:02
  Finished: -

Execution:
  PID:        12345
  Exit Code:  -
  Heartbeat:  2026-01-21 18:42:10 (2s ago)

Retry:
  Attempts:   0 / 3
  Next Retry: -

Files:
  Work Dir:  /tmp/barn/jobs/job-9f83c/work
  Logs Dir:  /tmp/barn/jobs/job-9f83c/logs

--- stdout.log (last 10 lines) ---
frame=  100 fps=30 q=28.0 size=     256kB time=00:00:03.33 bitrate= 629.0kbits/s
frame=  200 fps=30 q=28.0 size=     512kB time=00:00:06.66 bitrate= 629.0kbits/s
...

4. JSON Output

{
  "id": "job-9f83c",
  "state": "running",
  "tag": "transcode",
  "command": ["ffmpeg", "-i", "input.mp4", "-c:v", "libx264", "output.mp4"],
  "created_at": "2026-01-21T18:40:01Z",
  "started_at": "2026-01-21T18:40:02Z",
  "finished_at": null,
  "pid": 12345,
  "exit_code": null,
  "error": null,
  "heartbeat": "2026-01-21T18:42:10Z",
  "retry_count": 0,
  "retry_at": null,
  "paths": {
    "job_dir": "/tmp/barn/jobs/job-9f83c",
    "work_dir": "/tmp/barn/jobs/job-9f83c/work",
    "logs_dir": "/tmp/barn/jobs/job-9f83c/logs"
  },
  "logs": {
    "stdout": "...",
    "stderr": "..."
  }
}

5. Log Display

When --logs is specified:

  • Show last N lines of stdout.log and stderr.log
  • Use tail-like behavior
  • Indicate if logs are truncated

6. Error Handling

  • Job not found: exit 1 with "Job not found: job-xyz"
  • Invalid job ID format: exit 1 with validation error

7. Tests Required

  • DescribeCommandTest.java: Test output formatting, error cases
  • Integration test: Create job, describe it, verify output

Acceptance Criteria

  • barn describe <id> shows detailed info
  • --logs includes log file contents
  • --manifest shows full manifest JSON
  • Job not found returns proper error
  • All output formats work
  • mvn verify passes
  • Tests have 80%+ coverage

Implementation Notes

For relative time display:

public static String relativeTime(Instant instant) {
    Duration elapsed = Duration.between(instant, Instant.now());
    if (elapsed.toSeconds() < 60) return elapsed.toSeconds() + "s ago";
    if (elapsed.toMinutes() < 60) return elapsed.toMinutes() + "m ago";
    // etc
}

For log tailing:

public static List<String> tailFile(Path file, int lines) {
    // Read last N lines efficiently
}

Definition of Done

  • Describe shows comprehensive job details
  • Logs can be included
  • Error handling is clear
  • All tests pass
<!-- github-import:issue:11 --> _Imported from GitHub samson-media/barn#11 — opened by **@daniel-samson** on 2026-01-21 12:39:06 UTC_ ## Overview Implement the `barn describe` command that shows detailed information about a specific job. ## Context - **Read first**: `README.md` (barn describe examples), `docs/jobs.md` (job directory layout) - **Depends on**: #8 (CLI framework), #4 (job model) ## Requirements ### 1. Describe Command `com.samsonmedia.barn.cli.DescribeCommand.java`: ```java @Command(name = "describe", description = "Show detailed job information") public class DescribeCommand extends BaseCommand { @Parameters(index = "0", description = "Job ID") private String jobId; @Option(names = {"--logs"}, description = "Include log file contents") private boolean includeLogs; @Option(names = {"--manifest"}, description = "Show full manifest") private boolean showManifest; @Override public Integer call() { // 1. Load job by ID // 2. Format detailed output // 3. Optionally include logs } } ``` ### 2. Usage Examples ```bash # Basic describe barn describe job-9f83c # Include logs barn describe job-9f83c --logs # Show manifest barn describe job-9f83c --manifest # JSON output barn describe job-9f83c --output=json ``` ### 3. Human-Readable Output ``` Job: job-9f83c ================================================================================ State: running Tag: transcode Command: ffmpeg -i input.mp4 -c:v libx264 output.mp4 Timestamps: Created: 2026-01-21 18:40:01 Started: 2026-01-21 18:40:02 Finished: - Execution: PID: 12345 Exit Code: - Heartbeat: 2026-01-21 18:42:10 (2s ago) Retry: Attempts: 0 / 3 Next Retry: - Files: Work Dir: /tmp/barn/jobs/job-9f83c/work Logs Dir: /tmp/barn/jobs/job-9f83c/logs --- stdout.log (last 10 lines) --- frame= 100 fps=30 q=28.0 size= 256kB time=00:00:03.33 bitrate= 629.0kbits/s frame= 200 fps=30 q=28.0 size= 512kB time=00:00:06.66 bitrate= 629.0kbits/s ... ``` ### 4. JSON Output ```json { "id": "job-9f83c", "state": "running", "tag": "transcode", "command": ["ffmpeg", "-i", "input.mp4", "-c:v", "libx264", "output.mp4"], "created_at": "2026-01-21T18:40:01Z", "started_at": "2026-01-21T18:40:02Z", "finished_at": null, "pid": 12345, "exit_code": null, "error": null, "heartbeat": "2026-01-21T18:42:10Z", "retry_count": 0, "retry_at": null, "paths": { "job_dir": "/tmp/barn/jobs/job-9f83c", "work_dir": "/tmp/barn/jobs/job-9f83c/work", "logs_dir": "/tmp/barn/jobs/job-9f83c/logs" }, "logs": { "stdout": "...", "stderr": "..." } } ``` ### 5. Log Display When `--logs` is specified: - Show last N lines of stdout.log and stderr.log - Use tail-like behavior - Indicate if logs are truncated ### 6. Error Handling - Job not found: exit 1 with "Job not found: job-xyz" - Invalid job ID format: exit 1 with validation error ### 7. Tests Required - `DescribeCommandTest.java`: Test output formatting, error cases - Integration test: Create job, describe it, verify output ## Acceptance Criteria - [ ] `barn describe <id>` shows detailed info - [ ] `--logs` includes log file contents - [ ] `--manifest` shows full manifest JSON - [ ] Job not found returns proper error - [ ] All output formats work - [ ] `mvn verify` passes - [ ] Tests have 80%+ coverage ## Implementation Notes For relative time display: ```java public static String relativeTime(Instant instant) { Duration elapsed = Duration.between(instant, Instant.now()); if (elapsed.toSeconds() < 60) return elapsed.toSeconds() + "s ago"; if (elapsed.toMinutes() < 60) return elapsed.toMinutes() + "m ago"; // etc } ``` For log tailing: ```java public static List<String> tailFile(Path file, int lines) { // Read last N lines efficiently } ``` ## Definition of Done - Describe shows comprehensive job details - Logs can be included - Error handling is clear - All tests pass
daniel added this to the M3: CLI Commands milestone 2026-10-04 19:28:08 +00:00
daniel added the cli label 2026-10-04 19:28:08 +00:00
Author
Owner

@daniel-samson commented on 2026-01-21 14:29:08 UTC:

Implemented barn describe command with tests

<!-- github-import:comment:3778428045 --> _**@daniel-samson** commented on 2026-01-21 14:29:08 UTC:_ Implemented barn describe command with tests
This repo is archived. You cannot comment on issues.