Sha256: 0a470f07223bea36d9c77b000768be59985453891f5465e1f628e7a1b204b8c5

Contents?: true

Size: 1.59 KB

Versions: 2

Compression:

Stored size: 1.59 KB

Contents

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

          @queue = :activity_queue

          # @private
          def self.perform(activity_aggregate_key)
            # get the activity properties from the key
            key_components  = activity_aggregate_key.split(':')
            entity_type     = key_components[2].safe_constantize
            entity_id       = key_components[3]

            # get the entity
            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)
            entity_trackers_feeds << entity.profile_feed_key

            # remove the aggregate key from the trackers' feeds and prepare the activity for garbage collection
            ::Tekeya.redis.multi do
              entity_trackers_feeds.each do |feed_key|
                if ::Tekeya.redis.zrank(feed_key, activity_aggregate_key)
                  # remove the activity aggregate key from the feed
                  ::Tekeya.redis.zrem(feed_key, activity_aggregate_key)
                  # decrement the activity counter
                  ::Tekeya.redis.decr("#{activity_aggregate_key}:counter")
                end
              end
            end

            # trim the tracker feed and cleanup
            collect_garbage [activity_aggregate_key]
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tekeya-0.0.2 lib/tekeya/feed/activity/resque/delete_activity.rb
tekeya-0.0.1 lib/tekeya/feed/activity/resque/delete_activity.rb