fix(downloads): purge old processing jobs via a hosted cleanup worker#641
fix(downloads): purge old processing jobs via a hosted cleanup worker#641kevinheneveld wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Why not handle the cleaning in the DownloadProcessingJobProcessor ?
There was a problem hiding this comment.
Good call — done in a1fbb94. Dropped the standalone DownloadProcessingJobCleanupService and folded the daily purge into DownloadProcessingJobProcessor, which already owns job-table maintenance (the startup ResetStuckJobsAsync). One worker instead of two.
| { | ||
| using var scope = _scopeFactory.CreateScope(); | ||
| var jobService = scope.ServiceProvider.GetRequiredService<IDownloadProcessingJobService>(); | ||
| await jobService.CleanupOldJobsAsync(RetentionDays); |
There was a problem hiding this comment.
That method should be update so the actual cleaning logic does not stays in the infrastructure layer
There was a problem hiding this comment.
Agreed — also in a1fbb94. The retention policy (terminal statuses + age cutoff) now lives in the application DownloadProcessingJobService; the repository method is reduced to a thin DeleteCompletedBeforeAsync(statuses, cutoffUtc) that just runs the delete it's handed.
Addresses review feedback on Listenarrs#641: - Remove the standalone DownloadProcessingJobCleanupService and run the daily retention purge from DownloadProcessingJobProcessor, which already owns job-table maintenance (startup stuck-job reset). One worker, not two. - Move the retention policy (terminal statuses + age cutoff) out of the EF repository and into the application service; the repository method is now a thin DeleteCompletedBeforeAsync parameterized by that policy. Cleanup tests are rehomed to drive the processor end-to-end through the moved policy. Behavior is unchanged: terminal jobs older than 7 days are purged shortly after startup and then daily. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Addresses review feedback on Listenarrs#641: - Remove the standalone DownloadProcessingJobCleanupService and run the daily retention purge from DownloadProcessingJobProcessor, which already owns job-table maintenance (startup stuck-job reset). One worker, not two. - Move the retention policy (terminal statuses + age cutoff) out of the EF repository and into the application service; the repository method is now a thin DeleteCompletedBeforeAsync parameterized by that policy. Cleanup tests are rehomed to drive the processor end-to-end through the moved policy. Behavior is unchanged: terminal jobs older than 7 days are purged shortly after startup and then daily. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Thanks for the review @T4g1 — both points addressed in a1fbb94 (added on top, no force-push):
Behavior is unchanged (terminal jobs older than 7 days purged shortly after startup, then daily). Cleanup tests rehomed to drive the processor end-to-end through the moved policy. |
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>
Addresses review feedback on Listenarrs#641: - Remove the standalone DownloadProcessingJobCleanupService and run the daily retention purge from DownloadProcessingJobProcessor, which already owns job-table maintenance (startup stuck-job reset). One worker, not two. - Move the retention policy (terminal statuses + age cutoff) out of the EF repository and into the application service; the repository method is now a thin DeleteCompletedBeforeAsync parameterized by that policy. Cleanup tests are rehomed to drive the processor end-to-end through the moved policy. Behavior is unchanged: terminal jobs older than 7 days are purged shortly after startup and then daily. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
a1fbb94 to
d8990ef
Compare
Addresses the 3a (job retention) portion of #640.
IDownloadProcessingJobService.CleanupOldJobsAsync(retentionDays)already existed (and is implemented inEfDownloadProcessingJobRepository) but had no caller, soDownloadProcessingJobsgrew unbounded on long-running instances — and every queue-snapshot reconciliation that queries this table pays for the bloat.This adds
DownloadProcessingJobCleanupService, a hostedBackgroundServicethat purges terminal (Completed/Failed) jobs older than a 7-day retention window shortly after startup and then daily.Notes
CleanupOldJobsAsyncdefault) to keep this change migration-free; making it configurable is an easy follow-up.RunCleanupAsyncso it can be exercised directly in tests without driving the background loop.HostedServiceRegistrationExtensions.Tests
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.