Class: PyrRules::EventSubscriber
- Inherits:
-
Object
- Object
- PyrRules::EventSubscriber
- Defined in:
- app/rules/pyr_rules/event_subscriber.rb
Instance Method Summary collapse
- #connect ⇒ Object
- #disconnect ⇒ Object
-
#initialize ⇒ EventSubscriber
constructor
A new instance of EventSubscriber.
Constructor Details
#initialize ⇒ EventSubscriber
Returns a new instance of EventSubscriber.
4 5 |
# File 'app/rules/pyr_rules/event_subscriber.rb', line 4 def initialize end |
Instance Method Details
#connect ⇒ Object
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. do |channel, | puts "##{channel}: #{}" @redis.unsubscribe if == "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 |
#disconnect ⇒ Object
31 32 33 |
# File 'app/rules/pyr_rules/event_subscriber.rb', line 31 def disconnect @redis.unsubscribe end |