class Zulu::TopicDistribution

Constants

LIST

Public Class Methods

new(options={}) click to toggle source
# File lib/zulu/topic_distribution.rb, line 14
def initialize(options={})
  @id  = options[:id]
  @now = options[:now]
end
pop(timeout=nil) click to toggle source
# File lib/zulu/topic_distribution.rb, line 9
def self.pop(timeout=nil)
  _, options = Zulu.redis.brpop(LIST, timeout: timeout)
  options and new(Oj.load(options))
end
push(distribution) click to toggle source
# File lib/zulu/topic_distribution.rb, line 5
def self.push(distribution)
  Zulu.redis.lpush(LIST, distribution.to_json)
end

Public Instance Methods

==(other) click to toggle source
# File lib/zulu/topic_distribution.rb, line 31
def ==(other)
  to_hash == other.to_hash
end
now() click to toggle source
# File lib/zulu/topic_distribution.rb, line 19
def now
  @now
end
process() click to toggle source
# File lib/zulu/topic_distribution.rb, line 47
def process
  subscriptions.each do |subscription|
    Http.post(subscription.callback, form: {now: now})
  end
end
save() click to toggle source
# File lib/zulu/topic_distribution.rb, line 43
def save
  self.class.push(self)
end
subscriptions() click to toggle source
# File lib/zulu/topic_distribution.rb, line 27
def subscriptions
  topic.subscriptions.map {|sid| Subscription.new(id: sid) }
end
to_hash() click to toggle source
# File lib/zulu/topic_distribution.rb, line 35
def to_hash
  {id: @id, now: @now}
end
to_json() click to toggle source
# File lib/zulu/topic_distribution.rb, line 39
def to_json
  Oj.dump(to_hash)
end
topic() click to toggle source
# File lib/zulu/topic_distribution.rb, line 23
def topic
  @topic ||= Topic.new(id: @id)
end