Skip to content

Instantly share code, notes, and snippets.

@yaauie
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaauie/0099d047d0069dfbb71c to your computer and use it in GitHub Desktop.
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.
# @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