Sha256: daef6818956b8d77b399d2e403cf0a7457ee670b5299f6d83f1fdda40efb446e

Contents?: true

Size: 1.1 KB

Versions: 9

Compression:

Stored size: 1.1 KB

Contents

module Tekeya
  module Feed
    module Activity
      module Resque
        # A resque worker to copy activities when an entity tracks another
        class FeedCopy
          include Tekeya::Feed::Activity::Resque

          @queue = :activity_queue

          # @private
          def self.perform(tracked_feed_key, tracker_feed_key)
            # get the keys to the activities so we can increment the counters later
            activity_keys = ::Tekeya.redis.zrange(tracked_feed_key, 0, -1)

            ::Tekeya.redis.multi do
              # copy the latest activities from the tracked entity to the tracker feed
              ::Tekeya.redis.zunionstore(tracker_feed_key, [tracker_feed_key, tracked_feed_key])

              # increment the activity counter
              activity_keys.each do |activity_key|
                activity_counter_key = "#{activity_key}:counter"
                ::Tekeya.redis.incr(activity_counter_key)
              end
            end

            # trim the tracker feed and cleanup
            collect_garbage trim_feed(tracker_feed_key)
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
tekeya-0.0.10 lib/tekeya/feed/activity/resque/feed_copy.rb
tekeya-0.0.9 lib/tekeya/feed/activity/resque/feed_copy.rb
tekeya-0.0.7 lib/tekeya/feed/activity/resque/feed_copy.rb
tekeya-0.0.6 lib/tekeya/feed/activity/resque/feed_copy.rb
tekeya-0.0.5 lib/tekeya/feed/activity/resque/feed_copy.rb
tekeya-0.0.4 lib/tekeya/feed/activity/resque/feed_copy.rb
tekeya-0.0.3 lib/tekeya/feed/activity/resque/feed_copy.rb
tekeya-0.0.2 lib/tekeya/feed/activity/resque/feed_copy.rb
tekeya-0.0.1 lib/tekeya/feed/activity/resque/feed_copy.rb