Sha256: 1bd2096fc6c4a662bafd8785488d591e6c2d1ca8218988b35405f64fcf859b62

Contents?: true

Size: 1.37 KB

Versions: 7

Compression:

Stored size: 1.37 KB

Contents

require 'multi_json'

module Weeter
  module Plugins
    module Subscription
      class Redis
        include Weeter::Plugins::Net::Redis

        def initialize(client_app_config)
          @config = client_app_config
        end

        def get_initial_filters(&block)
          deferred_get = redis.get(@config.subscriptions_key) do |value|
            if value.nil?
              raise "Expected to find subscription data at redis key #{@config.subscriptions_key}"
            end
            yield MultiJson.decode(value)
          end
          deferred_get.errback do |message|
            Weeter.logger.error(message)
          end
        end

        def listen_for_filter_update(tweet_consumer)
          channel = @config.subscriptions_changed_channel
          pub_sub_redis.subscribe(channel) do |message|
            Weeter.logger.info [:message, channel, message]
            Weeter.logger.info("Retrieving updated filters from redis")
            get_initial_filters do |filter_params|
              Weeter.logger.info("Triggering reconnect Twitter stream with new filters")
              tweet_consumer.reconnect(filter_params)
            end
          end
        end

      protected

        def redis
          @redis ||= create_redis_client
        end

        def pub_sub_redis
          @pub_sub_redis ||= create_redis_client.pubsub
        end

      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
weeter-0.19.4 lib/weeter/plugins/subscription/redis.rb
weeter-0.19.3 lib/weeter/plugins/subscription/redis.rb
weeter-0.19.2 lib/weeter/plugins/subscription/redis.rb
weeter-0.19.1 lib/weeter/plugins/subscription/redis.rb
weeter-0.19.0 lib/weeter/plugins/subscription/redis.rb
weeter-0.18.0 lib/weeter/plugins/subscription/redis.rb
weeter-0.17.0 lib/weeter/plugins/subscription/redis.rb