admin/plugin: delete job_detail files when jobs are pruned from memory (#8722)

* admin/plugin: delete job_detail files when jobs are pruned from memory

pruneTrackedJobsLocked evicts the oldest terminal jobs from the in-memory
tracker when the total exceeds maxTrackedJobsTotal (1000). However the
dedicated per-job detail files in jobs/job_details/ were never removed,
causing them to accumulate indefinitely on disk.

Add ConfigStore.DeleteJobDetail and call it from pruneTrackedJobsLocked so
that the file is cleaned up together with the in-memory entry. Deletion
errors are logged at verbosity level 2 and do not abort the prune.

* admin/plugin: add test for DeleteJobDetail

---------

Co-authored-by: Anton Ustyugov <anton@devops>
Co-authored-by: Chris Lu <chris.lu@gmail.com>
This commit is contained in:
Anton
2026-03-21 23:23:32 +02:00
committed by GitHub
parent 90277ceed5
commit 7f0cf72574
3 changed files with 76 additions and 1 deletions

View File

@@ -446,6 +446,30 @@ func (s *ConfigStore) LoadJobDetail(jobID string) (*TrackedJob, error) {
return &clone, nil
}
// DeleteJobDetail removes the persisted detail snapshot for a job.
// It is a no-op when the file does not exist.
func (s *ConfigStore) DeleteJobDetail(jobID string) error {
jobID, err := sanitizeJobID(jobID)
if err != nil {
return err
}
s.mu.Lock()
defer s.mu.Unlock()
if !s.configured {
delete(s.memJobDetails, jobID)
return nil
}
path := filepath.Join(s.baseDir, jobsDirName, jobDetailsDirName, jobDetailFileName(jobID))
err = os.Remove(path)
if err != nil && !os.IsNotExist(err) {
return fmt.Errorf("delete job detail: %w", err)
}
return nil
}
func (s *ConfigStore) SaveActivities(activities []JobActivity) error {
s.mu.Lock()
defer s.mu.Unlock()