feat: restore job history from saved files on startup#440
Merged
Conversation
When Ofelia restarts, job history is now restored from saved JSON files in the save folder. This addresses the issue where job history displayed in the web UI was lost on container restarts. New configuration options: - restore-history: Enable/disable history restoration (default: true when save-folder is configured) - restore-history-max-age: Maximum age of history files to restore (default: 24h) The feature: - Scans the save folder for *.json files on startup - Parses and matches executions to configured jobs by name - Respects the per-job history-limit setting - Only restores files within the configured max age - Never marks restored executions as "running" Closes #439
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
✅ Mutation Testing ResultsMutation Score: 80.95% (threshold: 60%)
What is mutation testing?Mutation testing measures test quality by introducing small changes (mutations) to the code and checking if tests detect them. A higher score means better test effectiveness.
|
There was a problem hiding this comment.
Pull request overview
This PR implements automatic restoration of job execution history from saved JSON files on Ofelia startup. When save-folder is configured, previously saved execution records are now read back and populated into the in-memory job history, making the web UI display persistent across restarts.
Key changes:
- Adds two new configuration options:
restore-history(default: true when save-folder is set) andrestore-history-max-age(default: 24h) - Implements history restoration logic that respects per-job
history-limitsettings and filters by file age - Comprehensive test coverage for edge cases including invalid JSON, missing jobs, and max-age filtering
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| middlewares/save.go | Adds new configuration fields for history restoration with helper methods for defaults |
| middlewares/restore.go | New file implementing the core history restoration logic from saved JSON files |
| middlewares/restore_test.go | Comprehensive unit tests covering restoration logic and configuration behavior |
| cli/daemon.go | Integrates history restoration into the daemon startup sequence |
| config/validator.go | Marks new configuration options as optional fields in validation |
- Fix gosec G304 by adding path containment validation and #nosec directive - Fix log message accuracy by tracking actual count of restored jobs - Add documentation comments to SaveConfig fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
restore-history(default: true) andrestore-history-max-age(default: 24h)history-limitsettingsProblem
When Ofelia restarts (container recreation, host reboot, etc.), job history displayed in the web UI is lost because it's stored only in memory. However, if
save-folderis configured, execution data is already persisted to disk as JSON files but never read back.Solution
On startup, if
save-folderis configured:*.jsonfilesrestore-history-max-ageare skipped)history-limit)New Configuration
Test plan
Closes #439
Relates to discussion #437