retry_on_exit_codes: Specific exit codes to retry (default: all)
2. Retry Calculator
com.samsonmedia.barn.jobs.RetryCalculator.java:
publicclassRetryCalculator{privatefinalJobsConfigconfig;publicbooleanshouldRetry(Jobjob){// Check if retries are enabledif(job.retryCount()>=getMaxRetries(job)){returnfalse;}// Check if exit code is retryableif(!isRetryableExitCode(job.exitCode())){returnfalse;}returntrue;}publicDurationcalculateDelay(intretryCount){// delay = base_delay * (multiplier ^ retry_count)doubledelaySeconds=config.retryDelaySeconds()*Math.pow(config.retryBackoffMultiplier(),retryCount);returnDuration.ofSeconds((long)delaySeconds);}publicInstantcalculateRetryAt(Jobjob){Durationdelay=calculateDelay(job.retryCount());returnInstant.now().plus(delay);}}
3. Retry State Management
When a job fails and should be retried:
Calculate next retry time
Update retry_count (increment by 1)
Update retry_at (next execution time)
Append to retry_history (previous attempt details)
Only execute jobs where retry_at <= now or retry_at is null
Log retry attempts clearly
// In scheduler loopOptional<Job>findNextQueued(){returnrepository.findAll().stream().filter(j->j.state()==JobState.QUEUED).filter(j->j.retryAt()==null||j.retryAt().isBefore(Instant.now())).min(Comparator.comparing(Job::createdAt));}
6. Output Display
When showing job status, include retry info:
Human format:
Job: job-9f83c
State: queued (retry scheduled)
Retries: 2/3
Next Retry: 2026-01-21 18:44:00 (in 2m 30s)
Retry History:
Attempt 1: exit=1 at 2026-01-21 18:40:01 - Connection timeout
Attempt 2: exit=1 at 2026-01-21 18:41:30 - Connection timeout
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Imported from GitHub samson-media/barn#20 — opened by @daniel-samson on 2026-01-21 12:42:45 UTC
Overview
Implement the retry mechanism with exponential backoff for failed jobs.
Context
docs/config.md(retry behavior section)Requirements
1. Retry Configuration
From
docs/config.md:max_retries: Maximum retry attempts (default: 3)retry_delay_seconds: Initial delay (default: 30)retry_backoff_multiplier: Exponential multiplier (default: 2.0)retry_on_exit_codes: Specific exit codes to retry (default: all)2. Retry Calculator
com.samsonmedia.barn.jobs.RetryCalculator.java:3. Retry State Management
When a job fails and should be retried:
retry_count(increment by 1)retry_at(next execution time)retry_history(previous attempt details)QUEUED4. Retry History File
retry_historyfile format (append-only):5. Scheduler Integration
The scheduler should:
retry_atfor queued jobsretry_at <= noworretry_atis null6. Output Display
When showing job status, include retry info:
Human format:
JSON format:
7. Per-Job Retry Override
From CLI:
Store in manifest.json and use instead of global config.
8. Tests Required
RetryCalculatorTest.java: Test delay calculation, retry eligibilityRetrySchedulerTest.java: Test job requeuing with delayAcceptance Criteria
retry_on_exit_codesfilter worksmvn verifypassesImplementation Notes
Exponential backoff formula:
Consider adding jitter to prevent thundering herd:
Definition of Done
@daniel-samson commented on 2026-01-21 15:21:06 UTC:
Implemented retry mechanism with exponential backoff:
New Files:
src/main/java/com/samsonmedia/barn/jobs/RetryCalculator.java: Calculates retry eligibility and delays with exponential backoffsrc/test/java/com/samsonmedia/barn/jobs/RetryCalculatorTest.java: Comprehensive tests for retry logicUpdated Files:
JobRunner.java: Integrated retry handling - automatically schedules retries for failed jobsJobRepository.java: EnhancedscheduleRetry()to record retry historyFeatures:
delay = base_delay * (multiplier ^ retry_count)retryOnExitCodesfilter (empty = retry all non-zero)retry_historyfileJobResult.retryScheduledfield to indicate pending retryDelay Schedule (with defaults):
All 765 tests pass.