module OstScheduler
Constants
- TIMEOUT_SCHEDULER
- TIME_PERIOD
Public Instance Methods
each_delayed(&block)
click to toggle source
# File lib/ost-scheduler.rb, line 13 def each_delayed(&block) loop do now = Time.now.to_i min_time = now - range_period items = redis.call("ZRANGEBYSCORE",@key , min_time, now) if !items.count.zero? items.each do |item| block.call(item) end redis.call("ZREMRANGEBYSCORE",@key , min_time, now) end sleep(TIMEOUT_SCHEDULER.to_i) break if @stopping end end
items()
click to toggle source
# File lib/ost-scheduler.rb, line 35 def items if redis.call("TYPE", @key) == "zset" redis.call("ZRANGE", @key, 0, -1) else redis.call("LRANGE", @key, 0, -1) end end
push_at(time,value)
click to toggle source
/class Queue
# File lib/ost-scheduler.rb, line 7 def push_at(time,value) score = time.to_i if time.class == Time redis.call("ZADD", @key, score, value) end
range_period()
click to toggle source
# File lib/ost-scheduler.rb, line 31 def range_period (TIME_PERIOD.to_i * 60 * 60) end
size()
click to toggle source
# File lib/ost-scheduler.rb, line 43 def size if redis.call("TYPE", @key) == "zset" redis.call("ZCARD", @key) else redis.call("LLEN", @key) end end