Created by: hsource
Motivation
When running clean
on large queues, it can take a long time when tons of entries are within the grace period. The cleanJobsInSet Lua script never reaches the limit and endlessly iterates through items. Since redis scripts are atomic, this can lock up the rest of the server.
Fix
For sorted sets, the timestamp is just the score. As such, if there's a limit, we can just immediately get all the relevant ones using ZRANGEBYSCORE
in one iteration that also filters out the timestamps within the grace period.
Testing
Added automated tests
NODE_ENV=test yarn mocha -- 'test/test_queue*' -g "clean completed"