fix(jobs): allow QUEUED -> FAILED state transition

Jobs can fail before they start running (e.g., command not found,
permission denied). Previously, the state machine only allowed
QUEUED -> RUNNING or CANCELED, so jobs that failed to start would
stay stuck in QUEUED state with the scheduler retrying endlessly.

Now jobs can transition directly from QUEUED to FAILED, properly
recording the error message for commands that cannot be executed.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Daniel SamsonandClaude Opus 4.5 committed 2026-01-21 22:11:53 +00:00
1 parent 5d45b53abe
commit 555879be60
2 files changed
+8 -9

No files matched your search

@@ -12,7 +12,7 @@ import com.samsonmedia.barn.state.JobState;
*
* <p>Valid transitions:
* <ul>
* <li>QUEUED → RUNNING, CANCELED</li>
* <li>QUEUED → RUNNING, FAILED, CANCELED</li>
* <li>RUNNING → SUCCEEDED, FAILED, CANCELED</li>
* <li>FAILED → QUEUED (for retry)</li>
* <li>SUCCEEDED → (none, terminal)</li>
@@ -22,7 +22,7 @@ import com.samsonmedia.barn.state.JobState;
public final class JobStateMachine {
private static final Map<JobState, Set<JobState>> VALID_TRANSITIONS = Map.of(
JobState.QUEUED, Set.of(JobState.RUNNING, JobState.CANCELED),
JobState.QUEUED, Set.of(JobState.RUNNING, JobState.FAILED, JobState.CANCELED),
JobState.RUNNING, Set.of(JobState.SUCCEEDED, JobState.FAILED, JobState.CANCELED),
JobState.FAILED, Set.of(JobState.QUEUED), // For retry
JobState.SUCCEEDED, Set.of(),