fix: Add caps to celery work #301
Draft
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.
[UPDATE - this PR as is won't work unless I keep track of the start somewhere durable.. thinking.. tbd]
This PR removed bounds from cleanup_flare() function, causing it to process potentially millions of records instead of limited batches. This created too many concurrent file/socket connections (redis, postgres, GCS), exceeding the system's file descriptor limit (ulimit), resulting in "Error 24: Too many open files" in Celery.
Fix: Added back bounded processing (max 200 batches per run), used .iterator() for memory efficiency, and added throttling (time.sleep(0.005)) between file deletions to prevent connection spikes. Note that this means it will take more daily jobs to pay down the rows needing cleanup, but we'll do it in more manageable batches.
Also note this PR retains the changes that the original above PR was meant to solve (i.e., look at everything instead of just ids # 5000-500000, so we correctly process 1-4999 and 500001+).
Closes https://linear.app/getsentry/issue/CCMRG-1352/fix-ongoing-intermittent-celery-task-failures-reported-issue