feat(server): prune stale per-job log files on startup (#131)#135
Merged
Conversation
Per-job log files (${JOB_LOGS_DIR}/<jobId>.log) were never pruned, so the
directory grew without bound — one file per job run, forever. Mirror the
existing api_response_cache retention: a DB-owned, runtime-tunable window
swept once at startup, no rotation daemon, no schema churn.
JobRunner.live is the only startup site holding both logDir and pgClient,
so the sweep lives there beside markOrphansAsFailed. Retention defaults to
14 days (longer than the cache's 7 — logs are small and diagnostic-useful)
via a new job_log_retention_days AppSetting key. The sweep is best-effort:
a non-fatal IO error on one file is swallowed so it never aborts the sweep,
and a whole-sweep failure logs a warning and lets the server boot rather
than blocking startup. Filter by file mtime so any *.log name is handled
and "stale = not touched in N days" stays the semantic; non-log files in
the directory are left untouched.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ETHm6wCYdzFuB3kNEBayjF
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.
What
Adds a startup sweep that deletes per-job log files (
${JOB_LOGS_DIR}/<jobId>.log) older than a DB-owned retention window, mirroring the existingapi_response_cacheretention pattern. The job-log directory previously grew without bound (one file per job run, never pruned).AppSetting.JobLogRetentionDayskey — default 14 days, runtime-tunable via SQL, no schema churn (genericapp_settingkey/value store).FileSink.sweepBefore(logDir, cutoff)— best-effort*.logsweep filtered by file mtime; non-fatal IO errors per file are swallowed so one bad file never aborts the sweep; non-log files untouched.JobRunner.livestartup besidemarkOrphansAsFailed(only site holding bothlogDirandpgClient). A whole-sweep failure logs a warning and lets the server boot — retention is never a startup blocker.Fixes
Closes #131.
Testing
sbt test— full suite green (954 passed) via pre-push hook.TestJobLogSink.testSweepBeforeDeletesOldLogsOnly: old.logswept, fresh.log+ non-.logfile kept, count == 1. mtime pinned both sides to avoid filesystem-granularity flake.TestJobRunner(15) confirms the layer still constructs with the sweep wired.🤖 Generated with Claude Code
https://claude.ai/code/session_01ETHm6wCYdzFuB3kNEBayjF