Last active
August 29, 2015 14:05
-
-
Save yaauie/0099d047d0069dfbb71c to your computer and use it in GitHub Desktop.
Scan through all Resque Scheduler delayed jobs and emit the timestamps and payload of all matching jobs.
This file contains 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
# @param search [String, Regexp] | |
# @yieldparam time [Time] | |
# @yieldparam payload [String] | |
# @yieldreurn [void] | |
# @return [void] | |
def find_delayed_jobs(search) | |
return enum_for(__method__, search) unless block_given? | |
min = 0 | |
max = '+inf' | |
opts = {limit: [0, 1000]} | |
loop do | |
chunk = Resque.redis.zrangebyscore(:delayed_queue_schedule, min, max, opts) | |
return if chunk.empty? | |
chunk.each do |ts| | |
Resque.redis.lrange("delayed:#{ts}", 0, -1).each do |encoded| | |
yield(Time.at(ts.to_i), encoded) if encoded[search] | |
end | |
end | |
min = "(#{chunk.last}" | |
end | |
chunk = nil # scope | |
begin | |
end until chunk && chunk.empty? | |
end | |
# @param search [String, Regexp] | |
# @return ([Time], [String]) | |
def find_next_delayed_job(search) | |
find_delayed_jobs(search) do |time, payload| | |
return [time, payload] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment