Sha256: e7c271c70b5917bb1e0e5292f8c29a7faa08899fcf65096c00d15a016b2acbe9

Contents?: true

Size: 1.94 KB

Versions: 7

Compression:

Stored size: 1.94 KB

Contents

module Weeter
  module Plugins
    module Notification
      class Resque
        include Weeter::Plugins::Net::Redis

        def initialize(client_app_config)
          @config = client_app_config
        end

        def publish_tweet(tweet_item)
          resque_job = %Q|{"class":"WeeterPublishTweetJob","args":[#{tweet_item.to_json}],"jid": "#{SecureRandom.hex(12)}"}|
          Weeter.logger.info("Publishing tweet #{tweet_item['id']} from user #{tweet_item['user']['id_str']}: #{tweet_item['text']}")
          enqueue(resque_job)
        end

        def delete_tweet(tweet_item)
          resque_job = %Q|{"class":"WeeterDeleteTweetJob","args":[#{tweet_item.to_json}],"jid": "#{SecureRandom.hex(12)}"}|
          Weeter.logger.info("Deleting tweet #{tweet_item['id']} for user #{tweet_item['user']['id_str']}")
          enqueue(resque_job)
        end

        def notify_missed_tweets(tweet_item)
          resque_job = %Q|{"class":"WeeterMissedTweetsJob","args":[#{tweet_item.to_json}],"jid": "#{SecureRandom.hex(12)}"}|
          Weeter.logger.info("Notifying of missed tweets (#{tweet_item.missed_tweets_count}).")
          enqueue(resque_job)
        end

        def notify_rate_limiting_initiated(tweet_item, limited_keys)
          payload = tweet_item.to_hash.merge(:limited_keys => limited_keys)
          payload_json = MultiJson.encode(payload)
          resque_job = %Q|{"class":"WeeterRateLimitingInitiatedJob","args":[#{payload_json}],"jid": "#{SecureRandom.hex(12)}"}|
          Weeter.logger.info("Initiated rate limiting with tweet: #{payload_json}")
          enqueue(resque_job)
        end

      protected

        def redis
          @redis ||= begin
            @config.verify_redis_namespace_config
            create_redis_client
          end
        end

        def enqueue(job)
          redis.rpush(queue_key, job)
        end

        def queue_key
          "#{@config.redis_namespace}:#{@config.queue}"
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

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