Sha256: e64ef43e0814f4efa648524faf05e59d4b7633371b22d1870a16d0887f142f97

Contents?: true

Size: 1.37 KB

Versions: 5

Compression:

Stored size: 1.37 KB

Contents

module Tekeya
  module Feed
    module Activity
      module Resque
        # A resque worker to perform the activity fanout operation
        class ActivityFanout
          include Tekeya::Feed::Activity::Resque

          @queue = :activity_queue

          # @private
          def self.perform(entity_id, entity_type, activity_key, score)
            # get the entity class
            entity_type = entity_type.safe_constantize
            entity = entity_type.where(entity_type.entity_primary_key.to_sym => entity_id).first
            # we only need the feed keys of the trackers
            entity_trackers_feeds = entity.trackers.map(&:feed_key)
            # keep track of the keys we delete in the trim operation for garbage collection
            removed_keys = []

            # trim the profile feed
            removed_keys += trim_feed(entity.profile_feed_key)

            # Fanout the activity to the owner's trackers
            entity_trackers_feeds.each do |feed_key|
              # write the activity to the tracker's feed
              ::Tekeya.redis.multi do
                write_to_feed(feed_key, score, activity_key)
              end

              # trim the tracker's feed
              removed_keys += trim_feed(feed_key)
            end

            # cleanup the garbage
            collect_garbage removed_keys
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tekeya-0.0.10 lib/tekeya/feed/activity/resque/activity_fanout.rb
tekeya-0.0.9 lib/tekeya/feed/activity/resque/activity_fanout.rb
tekeya-0.0.7 lib/tekeya/feed/activity/resque/activity_fanout.rb
tekeya-0.0.6 lib/tekeya/feed/activity/resque/activity_fanout.rb
tekeya-0.0.5 lib/tekeya/feed/activity/resque/activity_fanout.rb