class RedisScheduler::ItemEnumerator

Enumerable class for iterating over everything in the schedule. Paginates calls to Redis under the hood (and is thus usable for very large schedules), but is not synchronized with write traffic and thus may return duplicates or skip items when paginating.

Supports random access with [], with the same caveats as above.

Constants

PAGE_SIZE

Public Class Methods

new(scheduler) click to toggle source
# File lib/redis-scheduler.rb, line 206
def initialize scheduler
  @scheduler = scheduler
end

Public Instance Methods

[](start, num=nil) click to toggle source
# File lib/redis-scheduler.rb, line 220
def [] start, num=nil
  elements = @scheduler.redis.zrange @scheduler.queue, start, start + (num || 0), :withscores => true
  v = elements.map do |entry, at|
    item = @scheduler.parse_entry entry
    [item, Time.at(at.to_f)]
  end
  num ? v : v.first
end
each() { |*x| ... } click to toggle source
# File lib/redis-scheduler.rb, line 211
def each
  start = 0
  while start < size
    elements = self[start, PAGE_SIZE]
    elements.each { |*x| yield(*x) }
    start += elements.size
  end
end
size() click to toggle source
# File lib/redis-scheduler.rb, line 229
def size; @scheduler.redis.zcard @scheduler.queue end