Last active
August 29, 2015 14:10
-
-
Save brasic/773596e2a9dd391d155a to your computer and use it in GitHub Desktop.
bulk-delete resque-scheduler entries
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
| require 'redis' | |
| require 'time' | |
| SET = "resque:delayed_queue_schedule" | |
| BUCKET_PREFIX = "resque:delayed" | |
| CHUNK_SIZE = 200 | |
| r = Redis.new | |
| range = [0, Time.parse("December 2 2014 15:00").to_i] | |
| buckets = r.zrangebyscore(SET, *range) | |
| puts "#{buckets.size} buckets to remove" | |
| removed = 0 | |
| format = ->(ts) { "#{BUCKET_PREFIX}:#{ts}" } | |
| buckets.each_slice(CHUNK_SIZE) do |chunk| | |
| if ENV['DELETE'] | |
| r.del(chunk.map(&format)) | |
| end | |
| puts "#{(removed += chunk.size)} / #{buckets.size}" | |
| end | |
| if ENV['DELETE'] | |
| r.zremrangebyscore(SET, *range) | |
| end | |
| puts "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment