refactor: refactor expired trash items job to bullmq#1000
Merged
Conversation
0a0a8fe to
9a4aee5
Compare
|
sg-gs
approved these changes
Mar 20, 2026
Member
sg-gs
left a comment
There was a problem hiding this comment.
Configuring this on Monday, to avoid surprises haha
Member
|
|
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.



How it works
The trash cleanup job was refactored from a plain NestJS cron task (with a Redis lock) to a BullMQ-backed queue.
The flow is split into two classes:
TrashCleanupScheduler— runs every 10 minutes via@Cron. It queries all tiers that have aTrashRetentionDaysfeature limit configured and enqueues one BullMQ job per tier into thetrash-cleanupqueue.TrashCleanupProcessor— a@Processor(BullMQ worker) withconcurrency: 2, meaning up to 2 tier jobs run in parallel at a time. For each job it:job_executionsrecord viastartJob.Duplicate job prevention
When the scheduler enqueues each tier it sets a deterministic
jobId:jobId: trash-cleanup:tier:${tier.id}BullMQ silently ignores
queue.addcalls for ajobIdthat already exists in the queue (waiting or active). This means if the cron fires again before the previous run finishes, no duplicate job is created for that tier.Env variables
REDIS_JOBS_CONNECTION_STRING=redis://@:
This is the Redis instance BullMQ uses for the queue. It is separate from the existing
REDIS_CONNECTION_STRINGused for general caching.