Skip to content

Commit

Permalink
Avoid skipping ranges when looping through queues (#720)
Browse files Browse the repository at this point in the history
Avoid negative ranges when looping through queues
  • Loading branch information
francesmcmullin authored Jul 1, 2022
1 parent 535989b commit 4bcc5d1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/sidekiq_unique_jobs/orphans/ruby_reaper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def entries(conn, queue, &block) # rubocop:disable Metrics/MethodLength

loop do
range_start = (page * page_size) - deleted_size

range_end = range_start + page_size - 1
entries = conn.lrange(queue_key, range_start, range_end)
page += 1
Expand All @@ -238,6 +239,9 @@ def entries(conn, queue, &block) # rubocop:disable Metrics/MethodLength
entries.each(&block)

deleted_size = initial_size - conn.llen(queue_key)

# The queue is growing, not shrinking, just keep looping
deleted_size = 0 if deleted_size.negative?
end
end

Expand Down

0 comments on commit 4bcc5d1

Please sign in to comment.