Skip to content

fix(downloads): purge old processing jobs via a hosted cleanup worker#641

Open
kevinheneveld wants to merge 1 commit into
Listenarrs:canaryfrom
kevinheneveld:fix/processing-job-retention
Open

fix(downloads): purge old processing jobs via a hosted cleanup worker#641
kevinheneveld wants to merge 1 commit into
Listenarrs:canaryfrom
kevinheneveld:fix/processing-job-retention

Conversation

@kevinheneveld
Copy link
Copy Markdown
Contributor

Addresses the 3a (job retention) portion of #640.

IDownloadProcessingJobService.CleanupOldJobsAsync(retentionDays) already existed (and is implemented in EfDownloadProcessingJobRepository) but had no caller, so DownloadProcessingJobs grew unbounded on long-running instances — and every queue-snapshot reconciliation that queries this table pays for the bloat.

This adds DownloadProcessingJobCleanupService, a hosted BackgroundService that purges terminal (Completed/Failed) jobs older than a 7-day retention window shortly after startup and then daily.

Notes

  • Retention is a constant (mirrors the existing CleanupOldJobsAsync default) to keep this change migration-free; making it configurable is an easy follow-up.
  • Cleanup logic is isolated in an internal RunCleanupAsync so it can be exercised directly in tests without driving the background loop.
  • Registered alongside the other hosted services in HostedServiceRegistrationExtensions.

Tests

  • Terminal jobs past the retention window are removed while recent and non-terminal jobs are retained.
  • No-op when nothing is eligible.
  • Service is registered as a hosted service.

Does not touch the 3b (orphan terminalization) part of #640 — that's a separate, more behavioral change and is left for discussion on the issue.

IDownloadProcessingJobService.CleanupOldJobsAsync existed but had no
caller, so the DownloadProcessingJobs table grew unbounded on
long-running instances. Every queue-snapshot reconciliation queries this
table (pending/all job download IDs for completed DDL items), so the
backlog also added steady per-snapshot cost.

Add DownloadProcessingJobCleanupService, a hosted BackgroundService that
purges terminal (Completed/Failed) jobs older than a 7-day retention
window shortly after startup and then daily. Retention is a constant to
keep this change migration-free; making it configurable is a follow-up.

Tests: terminal jobs past retention are removed while recent and
non-terminal jobs are retained; no-op when nothing is eligible; service
is registered as a hosted service.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@kevinheneveld kevinheneveld requested a review from a team June 1, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant