Class: Resque::Plugins::Pubsub::Broker

Inherits:
Object
  • Object
show all
Defined in:
lib/resque/plugins/pubsub/broker.rb

Class Method Summary collapse

Class Method Details

.perform(topic, message) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/resque/plugins/pubsub/broker.rb', line 19

def perform(topic, message)
  subscribers = Exchange.redis.smembers("#{topic}_subscribers")
  subscribers.each do |s|
    sinfo = JSON.parse(s)
    puts "[Broker] distributing to #{sinfo.inspect}"
    Broker.redis.sadd("#{sinfo['namespace']}:queues", "fanout:#{topic}")
    Broker.redis.rpush("#{sinfo['namespace']}:queue:fanout:#{topic}", { :class => sinfo['class'], :args => [message] }.to_json)
  end
end

.redisObject



13
14
15
16
17
# File 'lib/resque/plugins/pubsub/broker.rb', line 13

def redis
  return @redis if @redis
  client_to_copy = Resque.redis.client
  @redis = Redis.new(:host => client_to_copy.host, :port => client_to_copy.port, :thread_safe => true, :db => client_to_copy.db)
end