fix(bullmq): apply configurable job retention to prevent unbounded Redis growth#1
Open
apdelsm wants to merge 1 commit into
Open
fix(bullmq): apply configurable job retention to prevent unbounded Redis growth#1apdelsm wants to merge 1 commit into
apdelsm wants to merge 1 commit into
Conversation
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.
Problem
The BullMQ backend never sets
removeOnComplete/removeOnFail, and BullMQ keeps completed and failed jobs in Redis indefinitely by default. For recurring jobs this is a slow memory leak: every run leaves a job record behind forever.We hit this in a real deployment — a Redis instance sitting at ~94 MB "with no traffic", of which 31,315 keys were
bull:default:repeat:hermes:<job>:<ts>hashes (completed recurring-job runs,ttl=-1) from a job runningevery: '30s'. Thebull:default:completedset and the events stream were also growing unbounded.Fix
defaultJobOptions?: DefaultJobOptionstoBullMQBackendOptionsso callers can control retention (and attempts/backoff).removeOnComplete: { count: 1000 },removeOnFail: { count: 5000 }) so Redis no longer grows without limit out of the box; anything the caller passes is merged on top and takes precedence.defaultJobOptions) and the job scheduler's template (opts). This second part matters: jobs produced by a scheduler do not inherit the queue'sdefaultJobOptions, so without it recurring jobs would still pile up.Testing
deno task check,deno lint,deno fmtclean.deno task test— all BullMQ integration tests pass against a local Redis (7 passed), including a new regression test that asserts no completed jobs accumulate when retention is set.Defaults are conservative and easy to tune; happy to adjust the retention values or make them opt-in instead of on-by-default if you prefer.
🤖 Generated with Claude Code