Class: PyrRules::EventSubscriber

Inherits:
Object
  • Object
show all
Defined in:
app/rules/pyr_rules/event_subscriber.rb

Instance Method Summary collapse

Constructor Details

#initializeEventSubscriber

Returns a new instance of EventSubscriber.



4
5
# File 'app/rules/pyr_rules/event_subscriber.rb', line 4

def initialize
end

Instance Method Details

#connectObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/rules/pyr_rules/event_subscriber.rb', line 7

def connect 
	@redis = Redis.new
	begin
	  @redis.subscribe( "pyr_events" ) do |on|
	    on.subscribe do |channel, subscriptions|
	      puts "Subscribed to ##{channel} (#{subscriptions} subscriptions)"
	    end

	    on.message do |channel, message|
	      puts "##{channel}: #{message}"
	      @redis.unsubscribe if message == "exit"
	    end

	    on.unsubscribe do |channel, subscriptions|
	      puts "Unsubscribed from ##{channel} (#{subscriptions} subscriptions)"
	    end
	  end
	rescue Redis::BaseConnectionError => error
	  puts "#{error}, retrying in 1s"
	  sleep 1
	  retry
	end
end

#disconnectObject



31
32
33
# File 'app/rules/pyr_rules/event_subscriber.rb', line 31

def disconnect 
	@redis.unsubscribe
end